Debian Codegraph @

doc/docstrings/curl_getinfo.rst

raw
1 getinfo(option) -> Result
2
3 Extract and return information from a curl session,
4 decoding string data in Python's default encoding at the time of the call.
5 Corresponds to `curl_easy_getinfo`_ in libcurl.
6 The ``getinfo`` method should not be called unless
7 ``perform`` has been called and finished.
8
9 *option* is a constant corresponding to one of the
10 ``CURLINFO_*`` constants in libcurl. Most option constant names match
11 the respective ``CURLINFO_*`` constant names with the ``CURLINFO_`` prefix
12 removed, for example ``CURLINFO_CONTENT_TYPE`` is accessible as
13 ``pycurl.CONTENT_TYPE``. Exceptions to this rule are as follows:
14
15 - ``CURLINFO_FILETIME`` is mapped as ``pycurl.INFO_FILETIME``
16 - ``CURLINFO_COOKIELIST`` is mapped as ``pycurl.INFO_COOKIELIST``
17 - ``CURLINFO_CERTINFO`` is mapped as ``pycurl.INFO_CERTINFO``
18 - ``CURLINFO_RTSP_CLIENT_CSEQ`` is mapped as ``pycurl.INFO_RTSP_CLIENT_CSEQ``
19 - ``CURLINFO_RTSP_CSEQ_RECV`` is mapped as ``pycurl.INFO_RTSP_CSEQ_RECV``
20 - ``CURLINFO_RTSP_SERVER_CSEQ`` is mapped as ``pycurl.INFO_RTSP_SERVER_CSEQ``
21 - ``CURLINFO_RTSP_SESSION_ID`` is mapped as ``pycurl.INFO_RTSP_SESSION_ID``
22
23 The type of return value depends on the option, as follows:
24
25 - Options documented by libcurl to return an integer value return a
26 Python ``int``.
27 - Options documented by libcurl to return a floating point value
28 return a Python ``float``.
29 - Options documented by libcurl to return a string value
30 return a Python ``str``.
31 The data returned by libcurl is decoded using the
32 default string encoding at the time of the call.
33 If the data cannot be decoded using the default encoding, ``UnicodeDecodeError``
34 is raised. Use :ref:`getinfo_raw <getinfo_raw>`
35 to retrieve the data as ``bytes`` in these
36 cases.
37 - ``SSL_ENGINES`` and ``INFO_COOKIELIST`` return a list of strings.
38 The same encoding caveats apply; use :ref:`getinfo_raw <getinfo_raw>`
39 to retrieve the
40 data as a list of byte strings.
41 - ``INFO_CERTINFO`` returns a list with one element
42 per certificate in the chain, starting with the leaf; each element is a
43 sequence of *(key, value)* tuples where both ``key`` and ``value`` are
44 strings. String encoding caveats apply; use :ref:`getinfo_raw <getinfo_raw>`
45 to retrieve
46 certificate data as byte strings.
47 - For libcurl versions >= 7.45.0, ``CURLINFO_LASTSOCKET`` is aliased to
48 ``CURLINFO_ACTIVESOCKET`` to avoid unreliable results on some platforms.
49
50 Example usage::
51
52 import pycurl
53 c = pycurl.Curl()
54 c.setopt(pycurl.OPT_CERTINFO, 1)
55 c.setopt(pycurl.URL, "https://python.org")
56 c.setopt(pycurl.FOLLOWLOCATION, 1)
57 c.perform()
58 print(c.getinfo(pycurl.HTTP_CODE))
59 # --> 200
60 print(c.getinfo(pycurl.EFFECTIVE_URL))
61 # --> "https://www.python.org/"
62 certinfo = c.getinfo(pycurl.INFO_CERTINFO)
63 print(certinfo)
64 # --> [(('Subject', 'C = AU, ST = Some-State, O = PycURL test suite,
65 CN = localhost'), ('Issuer', 'C = AU, ST = Some-State,
66 O = PycURL test suite, OU = localhost, CN = localhost'),
67 ('Version', '0'), ...)]
68
69
70 Raises pycurl.error exception upon failure.
71
72 .. _curl_easy_getinfo:
73 https://curl.haxx.se/libcurl/c/curl_easy_getinfo.html