Skip to content
Myr

quickstart.rst

This file

Path

docs/user/quickstart.rst

462 lines · 13.1 KiB

Last changed by

Merge pull request #784 from Locker537/docs_fixKenneth Reitzbefore adoptioncb0fdd8

History of this file

Take it

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

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

lines 1–17why, one step back
1.. _quickstart:
23Quickstart4==========56.. module:: requests.models78Eager to get started? This page gives a good introduction in how to get started9with Requests. This assumes you already have Requests installed. If you do not,10head over to the :ref:`Installation <install>` section.1112First, make sure that:1314* Requests is :ref:`installed <install>`15* Requests is :ref:`up-to-date <updates>`1617

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

line 18why, one step back
18Let's get started with some simple examples.

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

lines 19–20why, one step back
19
20

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

line 21why, one step back
21Make a Request

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

lines 22–23why, one step back
22------------------
23

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

line 24why, one step back
24Making a request with Requests is very simple.

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

line 25why, one step back
25

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

line 26why, one step back
26Begin by importing the Requests module::

Merge pull request #784 from Locker537/docs_fixKenneth Reitzbefore adoptioncb0fdd8

line 27why, one step back
27

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

line 28why, one step back
28 >>> import requests

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

line 29why, one step back
29

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

lines 30–31why, one step back
30Now, let's try to get a webpage. For this example, let's get GitHub's public
31timeline ::

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

line 32why, one step back
32

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

lines 33–34why, one step back
33 >>> r = requests.get('https://github.com/timeline.json')
34

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

line 35why, one step back
35Now, we have a :class:`Response` object called ``r``. We can get all the

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

line 36why, one step back
36information we need from this object.

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

line 37why, one step back
37

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

lines 38–39why, one step back
38Requests' simple API means that all forms of HTTP request are as obvious. For
39example, this is how you make an HTTP POST request::

Merge pull request #784 from Locker537/docs_fixKenneth Reitzbefore adoptioncb0fdd8

line 40why, one step back
40

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

line 41why, one step back
41 >>> r = requests.post("http://httpbin.org/post")

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

line 42why, one step back
42

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

lines 43–44why, one step back
43Nice, right? What about the other HTTP request types: PUT, DELETE, HEAD and
44OPTIONS? These are all just as simple::

Merge pull request #784 from Locker537/docs_fixKenneth Reitzbefore adoptioncb0fdd8

line 45why, one step back
45

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

lines 46–65why, one step back
46 >>> r = requests.put("http://httpbin.org/put")
47 >>> r = requests.delete("http://httpbin.org/delete")48 >>> r = requests.head("http://httpbin.org/get")49 >>> r = requests.options("http://httpbin.org/get")5051That's all well and good, but it's also only the start of what Requests can52do.535455Passing Parameters In URLs56--------------------------5758You often want to send some sort of data in the URL's query string. If59you were constructing the URL by hand, this data would be given as key/value60pairs in the URL after a question mark, e.g. ``httpbin.org/get?key=val``.61Requests allows you to provide these arguments as a dictionary, using the62``params`` keyword argument. As an example, if you wanted to pass63``key1=value1`` and ``key2=value2`` to ``httpbin.org/get``, you would use the64following code::65

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

lines 66–68why, one step back
66 >>> payload = {'key1': 'value1', 'key2': 'value2'}
67 >>> r = requests.get("http://httpbin.org/get", params=payload)68

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

line 69why, one step back
69You can see that the URL has been correctly encoded by printing the URL::

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

line 70why, one step back
70

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

lines 71–72why, one step back
71 >>> print r.url
72 u'http://httpbin.org/get?key2=value2&key1=value1'

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

line 73why, one step back
73

Merge pull request #784 from Locker537/docs_fixKenneth Reitzbefore adoptioncb0fdd8

line 74why, one step back
74

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

lines 75–77why, one step back
75Response Content
76----------------77

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

lines 78–79why, one step back
78We can read the content of the server's response. Consider the GitHub timeline
79again::

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

line 80why, one step back
80

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

lines 81–82why, one step back
81 >>> import requests
82 >>> r = requests.get('https://github.com/timeline.json')

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

lines 83–88why, one step back
83 >>> r.text
84 '[{"repository":{"open_issues":0,"url":"https://github.com/...8586Requests will automatically decode content from the server. Most unicode87charsets are seamlessly decoded.88

Merge pull request #772 from Lukasa/developKenneth Reitzbefore adoption6464618

lines 89–92why, one step back
89When you make a request, Requests makes educated guesses about the encoding of
90the response based on the HTTP headers. The text encoding guessed by Requests91is used when you access ``r.text``. You can find out what encoding Requests is92using, and change it, using the ``r.encoding`` property::

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

line 93why, one step back
93

Merge pull request #772 from Lukasa/developKenneth Reitzbefore adoption6464618

lines 94–104why, one step back
94 >>> r.encoding
95 'utf-8'96 >>> r.encoding = 'ISO-8859-1'9798If you change the encoding, Requests will use the new value of ``r.encoding``99whenever you call ``r.text``.100101Requests will also use custom encodings in the event that you need them. If102you have created your own encoding and registered it with the ``codecs``103module, you can simply use the codec name as the value of ``r.encoding`` and104Requests will handle the decoding for you.

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

lines 105–115why, one step back
105
106Binary Response Content107-----------------------108109You can also access the response body as bytes, for non-text requests::110111 >>> r.content112 b'[{"repository":{"open_issues":0,"url":"https://github.com/...113114The ``gzip`` and ``deflate`` transfer-encodings are automatically decoded for you.115

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

line 116why, one step back
116For example, to create an image from binary data returned by a request, you can

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

lines 117–123why, one step back
117use the following code:
118119 >>> from PIL import Image120 >>> from StringIO import StringIO121 >>> i = Image.open(StringIO(r.content))122123

Added r.json documentation (document ALL the awesome features!)Danilo Bargenbefore adoption1164450

lines 124–136why, one step back
124JSON Response Content
125---------------------126127There's also a builtin JSON decoder, in case you're dealing with JSON data::128129 >>> import requests130 >>> r = requests.get('https://github.com/timeline.json')131 >>> r.json132 [{u'repository': {u'open_issues': 0, u'url': 'https://github.com/...133134In case the JSON decoding fails, ``r.json`` simply returns ``None``.135136

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

lines 137–149why, one step back
137Raw Response Content
138--------------------139140In the rare case that you'd like to get the absolute raw socket response from the server,141you can access ``r.raw``::142143 >>> r.raw144 <requests.packages.urllib3.response.HTTPResponse object at 0x101194810>145146 >>> r.raw.read(10)147 '\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03'148149

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

lines 150–151why, one step back
150Custom Headers
151--------------

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

line 152why, one step back
152

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

lines 153–154why, one step back
153If you'd like to add HTTP headers to a request, simply pass in a ``dict`` to the
154``headers`` parameter.

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

line 155why, one step back
155

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

line 156why, one step back
156For example, we didn't specify our content-type in the previous example::

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

line 157why, one step back
157

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

lines 158–161why, one step back
158 >>> import json
159 >>> url = 'https://api.github.com/some/endpoint'160 >>> payload = {'some': 'data'}161 >>> headers = {'content-type': 'application/json'}

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

line 162why, one step back
162

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

line 163why, one step back
163 >>> r = requests.post(url, data=json.dumps(payload), headers=headers)

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

line 164why, one step back
164

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

lines 165–168why, one step back
165
166More complicated POST requests167------------------------------168

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

lines 169–176why, one step back
169Typically, you want to send some form-encoded data — much like an HTML form.
170To do this, simply pass a dictionary to the `data` argument. Your171dictionary of data will automatically be form-encoded when the request is made::172173 >>> payload = {'key1': 'value1', 'key2': 'value2'}174 >>> r = requests.post("http://httpbin.org/post", data=payload)175 >>> print r.text176 {

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

line 177why, one step back
177 // ...snip... //

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

lines 178–181why, one step back
178 "form": {
179 "key2": "value2",180 "key1": "value1"181 },

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

line 182why, one step back
182 // ...snip... //

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

lines 183–188why, one step back
183 }
184185There are many times that you want to send data that is not form-encoded. If you pass in a ``string`` instead of a ``dict``, that data will be posted directly.186187For example, the GitHub API v3 accepts JSON-Encoded POST/PATCH data::188

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

lines 189–191why, one step back
189 >>> import json
190 >>> url = 'https://api.github.com/some/endpoint'191 >>> payload = {'some': 'data'}

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

line 192why, one step back
192

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

line 193why, one step back
193 >>> r = requests.post(url, data=json.dumps(payload))

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

lines 194–201why, one step back
194
195196POST a Multipart-Encoded File197-----------------------------198199Requests makes it simple to upload Multipart-encoded files::200201 >>> url = 'http://httpbin.org/post'

Merge pull request #752 from anentropic/patch-1Kenneth Reitzbefore adoption54842cd

line 202why, one step back
202 >>> files = {'file': open('report.xls', 'rb')}

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

lines 203–206why, one step back
203
204 >>> r = requests.post(url, files=files)205 >>> r.text206 {

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

line 207why, one step back
207 // ...snip... //

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

line 208why, one step back
208 "files": {

Merge pull request #752 from anentropic/patch-1Kenneth Reitzbefore adoption54842cd

line 209why, one step back
209 "file": "<censored...binary...data>"

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

line 210why, one step back
210 },

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

line 211why, one step back
211 // ...snip... //

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

lines 212–213why, one step back
212 }
213

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

line 214why, one step back
214You can set the filename explicitly::

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

lines 215–221why, one step back
215
216 >>> url = 'http://httpbin.org/post'217 >>> files = {'file': ('report.xls', open('report.xls', 'rb'))}218219 >>> r = requests.post(url, files=files)220 >>> r.text221 {

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

line 222why, one step back
222 // ...snip... //

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

lines 223–225why, one step back
223 "files": {
224 "file": "<censored...binary...data>"225 },

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

line 226why, one step back
226 // ...snip... //

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

lines 227–228why, one step back
227 }
228

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

line 229why, one step back
229If you want, you can send strings to be received as files::

Merge remote-tracking branch 'origin/develop' into developKenneth Reitzbefore adoption2a7811b

lines 230–231why, one step back
230
231 >>> url = 'http://httpbin.org/post'

Merge pull request #784 from Locker537/docs_fixKenneth Reitzbefore adoptioncb0fdd8

line 232why, one step back
232 >>> files = {'file': ('report.csv', 'some,data,to,send\nanother,row,to,send\n')}

Merge remote-tracking branch 'origin/develop' into developKenneth Reitzbefore adoption2a7811b

lines 233–236why, one step back
233
234 >>> r = requests.post(url, files=files)235 >>> r.text236 {

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

line 237why, one step back
237 // ...snip... //

Merge remote-tracking branch 'origin/develop' into developKenneth Reitzbefore adoption2a7811b

lines 238–240why, one step back
238 "files": {
239 "file": "some,data,to,send\\nanother,row,to,send\\n"240 },

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

line 241why, one step back
241 // ...snip... //

Merge remote-tracking branch 'origin/develop' into developKenneth Reitzbefore adoption2a7811b

lines 242–243why, one step back
242 }
243

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

lines 244–249why, one step back
244
245Response Status Codes246---------------------247248We can check the response status code::249

Merge remote-tracking branch 'origin/develop' into developKenneth Reitzbefore adoption6541ceb

line 250why, one step back
250 >>> r = requests.get('http://httpbin.org/get')

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

lines 251–262why, one step back
251 >>> r.status_code
252 200253254Requests also comes with a built-in status code lookup object for easy255reference::256257 >>> r.status_code == requests.codes.ok258 True259260If we made a bad request (non-200 response), we can raise it with261:class:`Response.raise_for_status()`::262

Merge pull request #784 from Locker537/docs_fixKenneth Reitzbefore adoptioncb0fdd8

lines 263–264why, one step back
263 >>> bad_r = requests.get('http://httpbin.org/status/404')
264 >>> bad_r.status_code

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

lines 265–266why, one step back
265 404
266

Merge pull request #784 from Locker537/docs_fixKenneth Reitzbefore adoptioncb0fdd8

line 267why, one step back
267 >>> bad_r.raise_for_status()

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

line 268why, one step back
268 Traceback (most recent call last):

Merge pull request #683 from jkleint/patch-1Kenneth Reitzbefore adoption38db8c2

lines 269–271why, one step back
269 File "requests/models.py", line 832, in raise_for_status
270 raise http_error271 requests.exceptions.HTTPError: 404 Client Error

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

line 272why, one step back
272

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

lines 273–274why, one step back
273But, since our ``status_code`` for ``r`` was ``200``, when we call
274``raise_for_status()`` we get::

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

lines 275–284why, one step back
275
276 >>> r.raise_for_status()277 None278279All is well.280281282Response Headers283----------------284

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

line 285why, one step back
285We can view the server's response headers using a Python dictionary::

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

lines 286–324why, one step back
286
287 >>> r.headers288 {289 'status': '200 OK',290 'content-encoding': 'gzip',291 'transfer-encoding': 'chunked',292 'connection': 'close',293 'server': 'nginx/1.0.4',294 'x-runtime': '148ms',295 'etag': '"e1ca502697e5c9317743dc078f67693f"',296 'content-type': 'application/json; charset=utf-8'297 }298299The dictionary is special, though: it's made just for HTTP headers. According to300`RFC 2616 <http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html>`_, HTTP301Headers are case-insensitive.302303So, we can access the headers using any capitalization we want::304305 >>> r.headers['Content-Type']306 'application/json; charset=utf-8'307308 >>> r.headers.get('content-type')309 'application/json; charset=utf-8'310311If a header doesn't exist in the Response, its value defaults to ``None``::312313 >>> r.headers['X-Random']314 None315316317Cookies318-------319320If a response contains some Cookies, you can get quick access to them::321322 >>> url = 'http://httpbin.org/cookies/set/requests-is/awesome'323 >>> r = requests.get(url)324

update documentation to correspond to new cookie APIShivaram Lingamnenibefore adoptionfdd0821

lines 325–326why, one step back
325 >>> r.cookies['requests-is']
326 'awesome'

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

lines 327–341why, one step back
327
328To send your own cookies to the server, you can use the ``cookies``329parameter::330331 >>> url = 'http://httpbin.org/cookies'332 >>> cookies = dict(cookies_are='working')333334 >>> r = requests.get(url, cookies=cookies)335 >>> r.text336 '{"cookies": {"cookies_are": "working"}}'337338339Basic Authentication340--------------------341

Merge pull request #787 from kayzh/developKenneth Reitzbefore adoptionbbf1946

line 342why, one step back
342Many web services require authentication. There are many different types of

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

lines 343–374why, one step back
343authentication, but the most common is HTTP Basic Auth.
344345Making requests with Basic Auth is extremely simple::346347 >>> from requests.auth import HTTPBasicAuth348 >>> requests.get('https://api.github.com/user', auth=HTTPBasicAuth('user', 'pass'))349 <Response [200]>350351Due to the prevalence of HTTP Basic Auth, requests provides a shorthand for352this authentication method::353354 >>> requests.get('https://api.github.com/user', auth=('user', 'pass'))355 <Response [200]>356357Providing the credentials as a tuple in this fashion is functionally equivalent358to the ``HTTPBasicAuth`` example above.359360361Digest Authentication362---------------------363364Another popular form of web service protection is Digest Authentication::365366 >>> from requests.auth import HTTPDigestAuth367 >>> url = 'http://httpbin.org/digest-auth/auth/user/pass'368 >>> requests.get(url, auth=HTTPDigestAuth('user', 'pass'))369 <Response [200]>370371372OAuth Authentication373--------------------374

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

lines 375–378why, one step back
375Miguel Araujo's `requests-oauth <http://pypi.python.org/pypi/requests-oauth>`_
376project provides a simple interface for establishing OAuth connections.377Documentation and examples can be found on the requests-oauth378`git repository <https://github.com/maraujop/requests-oauth>`_.

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

lines 379–383why, one step back
379
380381Redirection and History382-----------------------383

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

lines 384–385why, one step back
384Requests will automatically perform location redirection while using the GET
385and OPTIONS verbs.

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

line 386why, one step back
386

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

lines 387–388why, one step back
387GitHub redirects all HTTP requests to HTTPS. We can use the ``history`` method
388of the Response object to track redirection. Let's see what Github does::

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

lines 389–398why, one step back
389
390 >>> r = requests.get('http://github.com')391 >>> r.url392 'https://github.com/'393 >>> r.status_code394 200395 >>> r.history396 [<Response [301]>]397398The :class:`Response.history` list contains a list of the

Merge pull request #721 from karlcow/developKenneth Reitzbefore adoptionc3ab38e

line 399why, one step back
399:class:`Request` objects that were created in order to complete the request. The list is sorted from the oldest to the most recent request.

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

line 400why, one step back
400

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

lines 401–402why, one step back
401If you're using GET or OPTIONS, you can disable redirection handling with the
402``allow_redirects`` parameter::

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

lines 403–409why, one step back
403
404 >>> r = requests.get('http://github.com', allow_redirects=False)405 >>> r.status_code406 301407 >>> r.history408 []409

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

lines 410–411why, one step back
410If you're using POST, PUT, PATCH, DELETE or HEAD, you can enable
411redirection as well::

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

lines 412–422why, one step back
412
413 >>> r = requests.post('http://github.com', allow_redirects=True)414 >>> r.url415 'https://github.com/'416 >>> r.history417 [<Response [301]>]418419420Timeouts421--------422

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

lines 423–424why, one step back
423You can tell requests to stop waiting for a response after a given number of
424seconds with the ``timeout`` parameter::

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

lines 425–430why, one step back
425
426 >>> requests.get('http://github.com', timeout=0.001)427 Traceback (most recent call last):428 File "<stdin>", line 1, in <module>429 requests.exceptions.Timeout: Request timed out.430

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

line 431why, one step back
431.. admonition:: Note:

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

line 432why, one step back
432

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

lines 433–434why, one step back
433 ``timeout`` only effects the connection process itself, not the
434 downloading of the response body.

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

lines 435–447why, one step back
435
436437Errors and Exceptions438---------------------439440In the event of a network problem (e.g. DNS failure, refused connection, etc),441Requests will raise a :class:`ConnectionError` exception.442443In the event of the rare invalid HTTP response, Requests will raise444an :class:`HTTPError` exception.445446If a request times out, a :class:`Timeout` exception is raised.447

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

lines 448–449why, one step back
448If a request exceeds the configured number of maximum redirections, a
449:class:`TooManyRedirects` exception is raised.

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

lines 450–453why, one step back
450
451All exceptions that Requests explicitly raises inherit from452:class:`requests.exceptions.RequestException`.453

Merge pull request #619 from Lukasa/developKenneth Reitzbefore adoptionad8205f

lines 454–458why, one step back
454You can refer to :ref:`Configuration API Docs <configurations>` for immediate
455raising of :class:`HTTPError` exceptions via the ``danger_mode`` option or456have Requests catch the majority of457:class:`requests.exceptions.RequestException` exceptions with the ``safe_mode``458option.

only import oauthlib in python2Kenneth Reitzbefore adoption661af1d

lines 459–462why, one step back
459
460-----------------------461462Ready for more? Check out the :ref:`advanced <advanced>` section.