Merge pull request #3513 from nateprewitt/doc_updates
Before adoption: this commit came in with the history the project adopted, so no landing records it.
doc updates
authored by Kenneth Reitz · committed by GitHub · parents f12166a, 1435cf5 · Browse files · 6 files·+45 added−57 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+45 added−57 removed
- other:+45 added−57 removed
Provenance
- Commit
786fb19- Tree
f02f66d- Author
Kenneth Reitz <me@kennethreitz.org>- Committer
GitHub <noreply@github.com>- Parent 1
f12166a- Parent 2
1435cf5
6 files changed+45 added−57 removed
modified:docs/community/faq.rst+2 added-4 removed
54 unmodified lines55 supported:56 57 * Python 2.658 * Python 2.759-* Python 3.160-* Python 3.259 * Python 3.360 * Python 3.463-* PyPy 1.964-* PyPy 2.261+* Python 3.562+* PyPy63 64 What are "hostname doesn't match" errors?65 -----------------------------------------66 20 unmodified linesmodified:docs/community/out-there.rst-11 removed
1 Integrations2 ============3 4-ScraperWiki5-------------6-7-`ScraperWiki <https://scraperwiki.com/>`_ is an excellent service that allows8-you to run Python, Ruby, and PHP scraper scripts on the web. Now, Requests9-v0.6.1 is available to use in your scrapers!10-11-To give it a try, simply::12-13- import requests14-4 Python for iOS5 --------------6 7 Requests is built into the wonderful `Python for iOS <https://itunes.apple.com/us/app/python-2.7-for-ios/id485729872?mt=Python8>`_ runtime!15 unmodified linesmodified:docs/dev/todo.rst+1 added-1 removed
39 unmodified lines40 - Python 2.741 - Python 3.342 - Python 3.443 - Python 3.544-- PyPy 1.944+- PyPy45 46 Google AppEngine is not officially supported although support is available47 with the `Requests-Toolbelt`_.48 12 unmodified linesmodified:docs/user/advanced.rst+29 added-31 removed
85 unmodified lines86 87 Request and Response Objects88 ----------------------------89 90-Whenever a call is made to ``requests.get()`` and friends you are doing two90+Whenever a call is made to ``requests.get()`` and friends, you are doing two91 major things. First, you are constructing a ``Request`` object which will be92 sent off to a server to request or query some resource. Second, a ``Response``93-object is generated once ``requests`` gets a response back from the server.94-The Response object contains all of the information returned by the server and93+object is generated once Requests gets a response back from the server.94+The ``Response`` object contains all of the information returned by the server and95 also contains the ``Request`` object you created originally. Here is a simple96 request to get some very important information from Wikipedia's servers::97 98 >>> r = requests.get('http://en.wikipedia.org/wiki/Monty_Python')113 unmodified lines212 the c_rehash utility supplied with OpenSSL.213 214 This list of trusted CAs can also be specified through the ``REQUESTS_CA_BUNDLE`` environment variable.215 216-Requests can also ignore verifying the SSL certificate if you set ``verify`` to False.216+Requests can also ignore verifying the SSL certificate if you set ``verify`` to False::217 218-::219-218 >>> requests.get('https://kennethreitz.com', verify=False)219 <Response [200]>220 221 By default, ``verify`` is set to True. Option ``verify`` only applies to host certs.17 unmodified lines239 240 CA Certificates241 ---------------242 245-By default Requests bundles a set of root CAs that it trusts, sourced from the243+By default, Requests bundles a set of root CAs that it trusts, sourced from the244 `Mozilla trust store`_. However, these are only updated once for each Requests245 version. This means that if you pin a Requests version your certificates can246 become extremely out of date.247 15 unmodified lines263 ---------------------264 265 By default, when you make a request, the body of the response is downloaded266 immediately. You can override this behaviour and defer downloading the response269-body until you access the :class:`Response.content <requests.Response.content>`267+body until you access the :attr:`Response.content <requests.Response.content>`268 attribute with the ``stream`` parameter::269 270 tarball_url = 'https://github.com/kennethreitz/requests/tarball/master'271 r = requests.get(tarball_url, stream=True)4 unmodified lines276 if int(r.headers['content-length']) < TOO_LONG:277 content = r.content278 ...279 282-You can further control the workflow by use of the :class:`Response.iter_content <requests.Response.iter_content>`283-and :class:`Response.iter_lines <requests.Response.iter_lines>` methods.280+You can further control the workflow by use of the :meth:`Response.iter_content() <requests.Response.iter_content>`281+and :meth:`Response.iter_lines() <requests.Response.iter_lines>` methods.282 Alternatively, you can read the undecoded body from the underlying283 urllib3 :class:`urllib3.HTTPResponse <urllib3.response.HTTPResponse>` at286-:class:`Response.raw <requests.Response.raw>`.284+:attr:`Response.raw <requests.Response.raw>`.285 286 If you set ``stream`` to ``True`` when making a request, Requests cannot287 release the connection back to the pool unless you consume all the data or call290-:class:`Response.close <requests.Response.close>`. This can lead to288+:meth:`Response.close <requests.Response.close>`. This can lead to289 inefficiency with connections. If you find yourself partially reading request290 bodies (or not reading them at all) while using ``stream=True``, you should291 consider using ``contextlib.closing`` (`documented here`_), like this::292 53 unmodified lines346 347 requests.post('http://some.url/chunked', data=gen())348 349 For chunked encoded responses, it's best to iterate over the data using352-:meth:`Response.iter_content() <requests.models.Response.iter_content>`. In350+:meth:`Response.iter_content() <requests.Response.iter_content>`. In351 an ideal situation you'll have set ``stream=True`` on the request, in which354-case you can iterate chunk-by-chunk by calling ``iter_content`` with a chunk355-size parameter of ``None``. If you want to set a maximum size of the chunk,356-you can set a chunk size parameter to any integer.352+case you can iterate chunk-by-chunk by calling ``iter_content`` with a ``chunk_size``353+parameter of ``None``. If you want to set a maximum size of the chunk,354+you can set a ``chunk_size`` parameter to any integer.355 356 357 .. _multipart:358 78 unmodified lines437 438 Any callable which is passed as the ``auth`` argument to a request method will439 have the opportunity to modify the request before it is dispatched.440 443-Authentication implementations are subclasses of ``requests.auth.AuthBase``,441+Authentication implementations are subclasses of :class:`AuthBase <requests.auth.AuthBase>`,442 and are easy to define. Requests provides two common authentication scheme445-implementations in ``requests.auth``: ``HTTPBasicAuth`` and ``HTTPDigestAuth``.443+implementations in ``requests.auth``: :class:`HTTPBasicAuth <requests.auth.HTTPBasicAuth>` and444+:class:`HTTPDigestAuth <requests.auth.HTTPDigestAuth>`.445 446 Let's pretend that we have a web service that will only respond if the447 ``X-Pizza`` header is set to a password value. Unlikely, but just go with it.448 21 unmodified lines470 471 Streaming Requests472 ------------------473 475-With :class:`requests.Response.iter_lines()` you can easily474+With :meth:`Response.iter_lines() <requests.Response.iter_lines>` you can easily475 iterate over streaming APIs such as the `Twitter Streaming476 API <https://dev.twitter.com/streaming/overview>`_. Simply477 set ``stream`` to ``True`` and iterate over the response with479-:class:`~requests.Response.iter_lines()`::478+:meth:`~requests.Response.iter_lines()`::479 480 import json481 import requests482 6 unmodified lines489 print(json.loads(line))490 491 .. warning::492 494- :class:`~requests.Response.iter_lines()` is not reentrant safe.493+ :meth:`~requests.Response.iter_lines()` is not reentrant safe.494 Calling this method multiple times causes some of the received data495 being lost. In case you need to call it from multiple places, use496 the resulting iterator object instead::497 169 unmodified lines667 commits is POST, which creates a new commit. As we're using the Requests repo,668 we should probably avoid making ham-handed POSTS to it. Instead, let's play669 with the Issues feature of GitHub.670 672-This documentation was added in response to Issue #482. Given that this issue673-already exists, we will use it as an example. Let's start by getting it.671+This documentation was added in response to672+`Issue #482 <https://github.com/kennethreitz/requests/issues/482>`_. Given that673+this issue already exists, we will use it as an example. Let's start by getting it.674 675 ::676 677 >>> r = requests.get('https://api.github.com/repos/kennethreitz/requests/issues/482')166 unmodified lines844 with the given prefix will use the given Transport Adapter.845 846 Many of the details of implementing a Transport Adapter are beyond the scope of847 this documentation, but take a look at the next example for a simple SSL use-848-case. For more than that, you might look at subclassing849-``requests.adapters.BaseAdapter``.848+case. For more than that, you might look at subclassing the849+:class:`BaseAdapter <requests.adapters.BaseAdapter>`.850 851 Example: Specific SSL Version852 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^853 3 unmodified lines857 that uses a version that isn't compatible with the default.858 859 You can use Transport Adapters for this by taking most of the existing860 implementation of HTTPAdapter, and adding a parameter *ssl_version* that gets861-passed-through to `urllib3`. We'll make a TA that instructs the library to use862-SSLv3:861+passed-through to `urllib3`. We'll make a Transport Adapter that instructs the862+library to use SSLv3::863 864-::865-864 import ssl865 866 from requests.adapters import HTTPAdapter867 from requests.packages.urllib3.poolmanager import PoolManager33 unmodified lines901 ---------------902 903 In unusual circumstances you may want to provide headers in an ordered manner. If you pass an ``OrderedDict`` to the ``headers`` keyword argument, that will provide the headers with an ordering. *However*, the ordering of the default headers used by Requests will be preferred, which means that if you override default headers in the ``headers`` keyword argument, they may appear out of order compared to other headers in that keyword argument.904 907-If this is problematic, users should consider setting the default headers on a :class:`Session <requests.Session>` object, by setting :data:`Session <requests.Session.headers>` to a custom ``OrderedDict``. That ordering will always be preferred.905+If this is problematic, users should consider setting the default headers on a :class:`Session <requests.Session>` object, by setting :attr:`Session <requests.Session.headers>` to a custom ``OrderedDict``. That ordering will always be preferred.906 907 .. _timeouts:908 909 Timeouts27 unmodified lines937 If the remote server is very slow, you can tell Requests to wait forever for938 a response, by passing None as a timeout value and then retrieving a cup of939 coffee.940 943-.. code-block:: python941+::942 943 r = requests.get('https://github.com', timeout=None)944 945 .. _`connect()`: http://linux.die.net/man/2/connectmodified:docs/user/quickstart.rst+10 added-10 removed
25 unmodified lines26 27 >>> import requests28 29 Now, let's try to get a webpage. For this example, let's get GitHub's public30-timeline ::30+timeline::31 32 >>> r = requests.get('https://api.github.com/events')33 34 Now, we have a :class:`Response <requests.Response>` object called ``r``. We can112 unmodified lines147 >>> r = requests.get('https://api.github.com/events')148 >>> r.json()149 [{u'repository': {u'open_issues': 0, u'url': 'https://github.com/...150 151-In case the JSON decoding fails, ``r.json`` raises an exception. For example, if151+In case the JSON decoding fails, ``r.json()`` raises an exception. For example, if152 the response gets a 204 (No Content), or if the response contains invalid JSON,153-attempting ``r.json`` raises ``ValueError: No JSON object could be decoded``.153+attempting ``r.json()`` raises ``ValueError: No JSON object could be decoded``.154 155-It should be noted that the success of the call to ``r.json`` does **not**155+It should be noted that the success of the call to ``r.json()`` does **not**156 indicate the success of the response. Some servers may return a JSON object in a157 failed response (e.g. error details with HTTP 500). Such JSON will be decoded158 and returned. To check that a request is successful, use159 ``r.raise_for_status()`` or check ``r.status_code`` is what you expect.278 unmodified lines438 HEAD.439 440 We can use the ``history`` property of the Response object to track redirection.441 442-The :meth:`Response.history <requests.Response.history>` list contains the442+The :attr:`Response.history <requests.Response.history>` list contains the443 :class:`Response <requests.Response>` objects that were created in order to444 complete the request. The list is sorted from the oldest to the most recent445 response.446 56 unmodified lines503 Errors and Exceptions504 ---------------------505 506 In the event of a network problem (e.g. DNS failure, refused connection, etc),507-Requests will raise a :class:`~requests.exceptions.ConnectionError` exception.507+Requests will raise a :exc:`~requests.exceptions.ConnectionError` exception.508 509 :meth:`Response.raise_for_status() <requests.Response.raise_for_status>` will510-raise an :class:`~requests.exceptions.HTTPError` if the HTTP request510+raise an :exc:`~requests.exceptions.HTTPError` if the HTTP request511 returned an unsuccessful status code.512 513-If a request times out, a :class:`~requests.exceptions.Timeout` exception is513+If a request times out, a :exc:`~requests.exceptions.Timeout` exception is514 raised.515 516 If a request exceeds the configured number of maximum redirections, a517-:class:`~requests.exceptions.TooManyRedirects` exception is raised.517+:exc:`~requests.exceptions.TooManyRedirects` exception is raised.518 519 All exceptions that Requests explicitly raises inherit from520-:class:`requests.exceptions.RequestException`.520+:exc:`requests.exceptions.RequestException`.521 522 -----------------------523 524 Ready for more? Check out the :ref:`advanced <advanced>` section.modified:docs/api.rst+3 added
61 unmodified lines62 63 .. autoclass:: requests.PreparedRequest64 :inherited-members:65 66+.. autoclass:: requests.adapters.BaseAdapter67+ :inherited-members:68+69 .. autoclass:: requests.adapters.HTTPAdapter70 :inherited-members:71 72 Authentication198 unmodified lines