api.rst
This file
Path
docs/api.rst
194 lines · 4.9 KiB
Last changed by
Merge pull request #1474 from Kwpolska/docfixKenneth Reitzbefore adoptiond83919a
History of this fileTake it
The walk stopped after 200 commits: lines older than a158abf point at it.
remove stuidly annoying email notificationsKenneth Reitzbefore adoptiona158abf
lines 1–2why, one step back1.. _api:2developer interfaceKenneth Reitzbefore adoption911e8ae
lines 3–4why, one step back3Developer Interface4===================remove stuidly annoying email notificationsKenneth Reitzbefore adoptiona158abf
lines 5–15why, one step back56.. module:: requests78This part of the documentation covers all the interfaces of Requests. For9parts where Requests depends on external libraries, we document the most10important right here and provide links to the canonical documentation.111213Main Interface14--------------15Merge pull request #1330 from Kwpolska/patch-1Kenneth Reitzbefore adoptiond2ba579
line 16why, one step back16All of Requests' functionality can be accessed by these 7 methods.remove stuidly annoying email notificationsKenneth Reitzbefore adoptiona158abf
lines 17–28why, one step back17They all return an instance of the :class:`Response <Response>` object.1819.. autofunction:: request2021.. autofunction:: head22.. autofunction:: get23.. autofunction:: post24.. autofunction:: put25.. autofunction:: patch26.. autofunction:: delete2728docs updateKenneth Reitzbefore adoption3ddcc99
lines 29–30why, one step back29Lower-Level Classes30~~~~~~~~~~~~~~~~~~~remove stuidly annoying email notificationsKenneth Reitzbefore adoptiona158abf
line 31why, one step back31docs updateKenneth Reitzbefore adoption3ddcc99
lines 32–37why, one step back32.. autoclass:: requests.Request33 :inherited-members:3435.. autoclass:: Response36 :inherited-members:37request sessionsKenneth Reitzbefore adoption9f89ebe
lines 38–39why, one step back38Request Sessions39----------------remove stuidly annoying email notificationsKenneth Reitzbefore adoptiona158abf
lines 40–43why, one step back4041.. autoclass:: Session42 :inherited-members:43Merge pull request #1298 from Lukasa/adapter_docKenneth Reitzbefore adoption2426eeb
lines 44–45why, one step back44.. autoclass:: requests.adapters.HTTPAdapter45 :inherited-members:remove stuidly annoying email notificationsKenneth Reitzbefore adoptiona158abf
line 46why, one step back46Merge pull request #1298 from Lukasa/adapter_docKenneth Reitzbefore adoption2426eeb
line 47why, one step back47remove stuidly annoying email notificationsKenneth Reitzbefore adoptiona158abf
lines 48–50why, one step back48Exceptions49~~~~~~~~~~50Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 51–55why, one step back51.. autoexception:: requests.exceptions.RequestException52.. autoexception:: requests.exceptions.ConnectionError53.. autoexception:: requests.exceptions.HTTPError54.. autoexception:: requests.exceptions.URLRequired55.. autoexception:: requests.exceptions.TooManyRedirectsremove stuidly annoying email notificationsKenneth Reitzbefore adoptiona158abf
lines 56–76why, one step back565758Status Code Lookup59~~~~~~~~~~~~~~~~~~6061.. autofunction:: requests.codes6263::6465 >>> requests.codes['temporary_redirect']66 3076768 >>> requests.codes.teapot69 4187071 >>> requests.codes['\o/']72 2007374Cookies75~~~~~~~76Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 77–79why, one step back77.. autofunction:: requests.utils.dict_from_cookiejar78.. autofunction:: requests.utils.cookiejar_from_dict79.. autofunction:: requests.utils.add_dict_to_cookiejarremove stuidly annoying email notificationsKenneth Reitzbefore adoptiona158abf
lines 80–84why, one step back808182Encodings83~~~~~~~~~84Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 85–87why, one step back85.. autofunction:: requests.utils.get_encodings_from_content86.. autofunction:: requests.utils.get_encoding_from_headers87.. autofunction:: requests.utils.get_unicode_from_responseremove stuidly annoying email notificationsKenneth Reitzbefore adoptiona158abf
lines 88–96why, one step back888990Classes91~~~~~~~9293.. autoclass:: requests.Response94 :inherited-members:9596.. autoclass:: requests.Requestno async anymoreKenneth Reitzbefore adoptionb3fbc81
lines 97–99why, one step back97 :inherited-members:9899.. autoclass:: requests.PreparedRequestremove stuidly annoying email notificationsKenneth Reitzbefore adoptiona158abf
lines 100–104why, one step back100 :inherited-members:101102.. _sessionapi:103104.. autoclass:: requests.SessionMerge pull request #1298 from Lukasa/adapter_docKenneth Reitzbefore adoption2426eeb
lines 105–107why, one step back105 :inherited-members:106107.. autoclass:: requests.adapters.HTTPAdapterremove stuidly annoying email notificationsKenneth Reitzbefore adoptiona158abf
lines 108–109why, one step back108 :inherited-members:109Merge pull request #1231 from davidfischer/docs-migration1.0Kenneth Reitzbefore adoption08cab48
lines 110–164why, one step back110111Migrating to 1.x112----------------113114This section details the main differences between 0.x and 1.x and is meant115to ease the pain of upgrading.116117118API Changes119~~~~~~~~~~~120121* ``Response.json`` is now a callable and not a property of a response.122123 ::124125 import requests126 r = requests.get('https://github.com/timeline.json')127 r.json() # This *call* raises an exception if JSON decoding fails128129* The ``Session`` API has changed. Sessions objects no longer take parameters.130 ``Session`` is also now capitalized, but it can still be131 instantiated with a lowercase ``session`` for backwards compatibility.132133 ::134135 s = requests.Session() # formerly, session took parameters136 s.auth = auth137 s.headers.update(headers)138 r = s.get('http://httpbin.org/headers')139140* All request hooks have been removed except 'response'.141142* Authentication helpers have been broken out into separate modules. See143 requests-oauthlib_ and requests-kerberos_.144145.. _requests-oauthlib: https://github.com/requests/requests-oauthlib146.. _requests-kerberos: https://github.com/requests/requests-kerberos147148* The parameter for streaming requests was changed from ``prefetch`` to149 ``stream`` and the logic was inverted. In addition, ``stream`` is now150 required for raw response reading.151152 ::153154 # in 0.x, passing prefetch=False would accomplish the same thing155 r = requests.get('https://github.com/timeline.json', stream=True)156 r.raw.read(10)157158* The ``config`` parameter to the requests method has been removed. Some of159 these options are now configured on a ``Session`` such as keep-alive and160 maximum number of redirects. The verbosity option should be handled by161 configuring logging.162163 ::164Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption636476e
lines 165–181why, one step back165 import requests166 import logging167168 # these two lines enable debugging at httplib level (requests->urllib3->httplib)169 # you will see the REQUEST, including HEADERS and DATA, and RESPONSE with HEADERS but without DATA.170 # the only thing missing will be the response.body which is not logged.171 import httplib172 httplib.HTTPConnection.debuglevel = 1173 174 logging.basicConfig() # you need to initialize logging, otherwise you will not see anything from requests175 logging.getLogger().setLevel(logging.DEBUG)176 requests_log = logging.getLogger("requests.packages.urllib3")177 requests_log.setLevel(logging.DEBUG)178 requests_log.propagate = True179 180 requests.get('http://httpbin.org/headers')181Merge pull request #1231 from davidfischer/docs-migration1.0Kenneth Reitzbefore adoption08cab48
lines 182–188why, one step back182183184Licensing185~~~~~~~~~186187One key difference that has nothing to do with the API is a change in the188license from the ISC_ license to the `Apache 2.0`_ license. The Apache 2.0Merge pull request #1474 from Kwpolska/docfixKenneth Reitzbefore adoptiond83919a
line 189why, one step back189license ensures that contributions to Requests are also covered by the ApacheMerge pull request #1231 from davidfischer/docs-migration1.0Kenneth Reitzbefore adoption08cab48
lines 190–194why, one step back1902.0 license.191192.. _ISC: http://opensource.org/licenses/ISC193.. _Apache 2.0: http://opensource.org/licenses/Apache-2.0194