Skip to content
Myr

api.rst

This file

Path

docs/api.rst

197 lines · 4.7 KiB

Last changed by

Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption636476e

History of this file

Take it

The walk stopped after 200 commits: lines older than 4837900 point at it.

digest works!Kenneth Reitzbefore adoption4837900

lines 1–2why, one step back
1.. _api:
2

developer interfaceKenneth Reitzbefore adoption911e8ae

lines 3–4why, one step back
3Developer Interface
4===================

digest works!Kenneth Reitzbefore adoption4837900

lines 5–28why, one step back
5
6.. 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--------------1516All of Request's functionality can be accessed by these 7 methods.17They all return an instance of the :class:`Response <Response>` object.1819.. autofunction:: request2021.. autofunction:: head22.. autofunction:: get23.. autofunction:: post24.. autofunction:: put25.. autofunction:: patch26.. autofunction:: delete2728

docs updateKenneth Reitzbefore adoption3ddcc99

lines 29–30why, one step back
29Lower-Level Classes
30~~~~~~~~~~~~~~~~~~~

digest works!Kenneth Reitzbefore adoption4837900

line 31why, one step back
31

docs updateKenneth Reitzbefore adoption3ddcc99

lines 32–37why, one step back
32.. autoclass:: requests.Request
33 :inherited-members:3435.. autoclass:: Response36 :inherited-members:37

request sessionsKenneth Reitzbefore adoption9f89ebe

lines 38–39why, one step back
38Request Sessions
39----------------

digest works!Kenneth Reitzbefore adoption4837900

lines 40–43why, one step back
40
41.. autoclass:: Session42 :inherited-members:43

Merge pull request #1298 from Lukasa/adapter_docKenneth Reitzbefore adoption2426eeb

lines 44–45why, one step back
44.. autoclass:: requests.adapters.HTTPAdapter
45 :inherited-members:

digest works!Kenneth Reitzbefore adoption4837900

line 46why, one step back
46

Merge pull request #1298 from Lukasa/adapter_docKenneth Reitzbefore adoption2426eeb

line 47why, one step back
47

digest works!Kenneth Reitzbefore adoption4837900

lines 48–99why, one step back
48Exceptions
49~~~~~~~~~~5051.. module:: requests5253.. autoexception:: RequestException54.. autoexception:: ConnectionError55.. autoexception:: HTTPError56.. autoexception:: URLRequired57.. autoexception:: TooManyRedirects585960Status Code Lookup61~~~~~~~~~~~~~~~~~~6263.. autofunction:: requests.codes6465::6667 >>> requests.codes['temporary_redirect']68 3076970 >>> requests.codes.teapot71 4187273 >>> requests.codes['\o/']74 2007576Cookies77~~~~~~~7879.. autofunction:: dict_from_cookiejar80.. autofunction:: cookiejar_from_dict81.. autofunction:: add_dict_to_cookiejar828384Encodings85~~~~~~~~~8687.. autofunction:: get_encodings_from_content88.. autofunction:: get_encoding_from_headers89.. autofunction:: get_unicode_from_response90.. autofunction:: decode_gzip919293Classes94~~~~~~~9596.. autoclass:: requests.Response97 :inherited-members:9899.. autoclass:: requests.Request

no async anymoreKenneth Reitzbefore adoptionb3fbc81

lines 100–102why, one step back
100 :inherited-members:
101102.. autoclass:: requests.PreparedRequest

digest works!Kenneth Reitzbefore adoption4837900

lines 103–107why, one step back
103 :inherited-members:
104105.. _sessionapi:106107.. autoclass:: requests.Session

Merge pull request #1298 from Lukasa/adapter_docKenneth Reitzbefore adoption2426eeb

lines 108–110why, one step back
108 :inherited-members:
109110.. autoclass:: requests.adapters.HTTPAdapter

digest works!Kenneth Reitzbefore adoption4837900

lines 111–112why, one step back
111 :inherited-members:
112

Merge pull request #1231 from davidfischer/docs-migration1.0Kenneth Reitzbefore adoption08cab48

lines 113–167why, one step back
113
114Migrating to 1.x115----------------116117This section details the main differences between 0.x and 1.x and is meant118to ease the pain of upgrading.119120121API Changes122~~~~~~~~~~~123124* ``Response.json`` is now a callable and not a property of a response.125126 ::127128 import requests129 r = requests.get('https://github.com/timeline.json')130 r.json() # This *call* raises an exception if JSON decoding fails131132* The ``Session`` API has changed. Sessions objects no longer take parameters.133 ``Session`` is also now capitalized, but it can still be134 instantiated with a lowercase ``session`` for backwards compatibility.135136 ::137138 s = requests.Session() # formerly, session took parameters139 s.auth = auth140 s.headers.update(headers)141 r = s.get('http://httpbin.org/headers')142143* All request hooks have been removed except 'response'.144145* Authentication helpers have been broken out into separate modules. See146 requests-oauthlib_ and requests-kerberos_.147148.. _requests-oauthlib: https://github.com/requests/requests-oauthlib149.. _requests-kerberos: https://github.com/requests/requests-kerberos150151* The parameter for streaming requests was changed from ``prefetch`` to152 ``stream`` and the logic was inverted. In addition, ``stream`` is now153 required for raw response reading.154155 ::156157 # in 0.x, passing prefetch=False would accomplish the same thing158 r = requests.get('https://github.com/timeline.json', stream=True)159 r.raw.read(10)160161* The ``config`` parameter to the requests method has been removed. Some of162 these options are now configured on a ``Session`` such as keep-alive and163 maximum number of redirects. The verbosity option should be handled by164 configuring logging.165166 ::167

Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption636476e

lines 168–184why, one step back
168 import requests
169 import logging170171 # these two lines enable debugging at httplib level (requests->urllib3->httplib)172 # you will see the REQUEST, including HEADERS and DATA, and RESPONSE with HEADERS but without DATA.173 # the only thing missing will be the response.body which is not logged.174 import httplib175 httplib.HTTPConnection.debuglevel = 1176 177 logging.basicConfig() # you need to initialize logging, otherwise you will not see anything from requests178 logging.getLogger().setLevel(logging.DEBUG)179 requests_log = logging.getLogger("requests.packages.urllib3")180 requests_log.setLevel(logging.DEBUG)181 requests_log.propagate = True182 183 requests.get('http://httpbin.org/headers')184

Merge pull request #1231 from davidfischer/docs-migration1.0Kenneth Reitzbefore adoption08cab48

lines 185–197why, one step back
185
186187Licensing188~~~~~~~~~189190One key difference that has nothing to do with the API is a change in the191license from the ISC_ license to the `Apache 2.0`_ license. The Apache 2.0192license ensures that contributions to requests are also covered by the Apache1932.0 license.194195.. _ISC: http://opensource.org/licenses/ISC196.. _Apache 2.0: http://opensource.org/licenses/Apache-2.0197