Skip to content
Myr

Add more interlinks between the documentation

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Also fixes up tense in a few cases, and adds the `intersphinx` extension so we can link to the urllib3 documentation when it is called out.

authored by Kevin Burke · committed by Kevin Burke · parent 99ebac7 · Browse files · 2 files+46 added−35 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+46 added−35 removed

  • other:+46 added−35 removed

2 files+46 added−35 removed

modified:docs/user/advanced.rst+40 added-34 removed
107 unmodified lines
108109 print(resp.status_code)110111Since you are not doing anything special with the ``Request`` object, you112prepare it immediately and modified the ``PreparedRequest`` object. You then112prepare it immediately and modify the ``PreparedRequest`` object. You then113send that with the other parameters you would have sent to ``requests.*`` or114``Sesssion.*``.115116However, the above code will lose some of the advantages of having a Requests117:class:`Session <requests.Session>` object. In particular,118:class:`Session <requests.Session>`-level state such as cookies will119not get applied to your request. To get a120:class:`PreparedRequest <requests.models.PreparedRequest>` with that state121applied, replace the call to ``Request.prepare()`` with a call to122``Session.prepare_request()``, like this::121applied, replace the call to :meth:`Request.prepare()122<requests.Request.prepare>` with a call to123:meth:`Session.prepare_request() <requests.Session.prepare_request>`, like this::124125 from requests import Request, Session126127 s = Session()
54 unmodified lines
182183Body Content Workflow184---------------------185185By default, when you make a request, the body of the response is downloaded immediately. You can override this behavior and defer downloading the response body until you access the :class:`Response.content` attribute with the ``stream`` parameter::186By default, when you make a request, the body of the response is downloaded187immediately. You can override this behavior and defer downloading the response188body until you access the :class:`Response.content <requests.Response.content>`189attribute with the ``stream`` parameter::190191 tarball_url = 'https://github.com/kennethreitz/requests/tarball/master'192 r = requests.get(tarball_url, stream=True)193
2 unmodified lines
196 if int(r.headers['content-length']) < TOO_LONG:197 content = r.content198 ...199196You can further control the workflow by use of the :class:`Response.iter_content` and :class:`Response.iter_lines` methods. Alternatively, you can read the undecoded body from the underlying urllib3 :class:`urllib3.HTTPResponse` at :class:`Response.raw`.200You can further control the workflow by use of the :class:`Response.iter_content <requests.Response.iter_content>` and :class:`Response.iter_lines <requests.Response.iter_lines>` methods. Alternatively, you can read the undecoded body from the underlying urllib3 :class:`urllib3.HTTPResponse <urllib3.response.HTTPResponse>` at :class:`Response.raw <requests.Response.raw>`.201202203Keep-Alive204----------
103 unmodified lines
308309Streaming Requests310------------------311308With ``requests.Response.iter_lines()`` you can easily iterate over streaming309APIs such as the `Twitter Streaming API <https://dev.twitter.com/docs/streaming-api>`_.310Simply set ``stream`` to ``True`` and iterate over the response with ``iter_lines()``::312With :class:`requests.Response.iter_lines()` you can easily313iterate over streaming APIs such as the `Twitter Streaming314API <https://dev.twitter.com/docs/streaming-api>`_. Simply315set ``stream`` to ``True`` and iterate over the response with316:class:`~requests.Response.iter_lines()`::317318 import json319 import requests320
50 unmodified lines
371372Encodings373^^^^^^^^^374369When you receive a response, Requests makes a guess at the encoding to use for370decoding the response when you call the ``Response.text`` method. Requests371will first check for an encoding in the HTTP header, and if none is present,372will use `chardet <http://pypi.python.org/pypi/chardet>`_ to attempt to guess373the encoding.375When you receive a response, Requests makes a guess at the encoding to376use for decoding the response when you access the :attr:`Response.text377<requests.Response.text>` attribute. Requests will first check for an378encoding in the HTTP header, and if none is present, will use `chardet379<http://pypi.python.org/pypi/chardet>`_ to attempt to guess the encoding.380375The only time Requests will not do this is if no explicit charset is present376in the HTTP headers **and** the ``Content-Type`` header contains ``text``. In377this situation,378`RFC 2616 <http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7.1>`_379specifies that the default charset must be ``ISO-8859-1``. Requests follows380the specification in this case. If you require a different encoding, you can381manually set the ``Response.encoding`` property, or use the raw382``Response.content``.381The only time Requests will not do this is if no explicit charset382is present in the HTTP headers **and** the ``Content-Type``383header contains ``text``. In this situation, `RFC 2616384<http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7.1>`_ specifies385that the default charset must be ``ISO-8859-1``. Requests follows the386specification in this case. If you require a different encoding, you can387manually set the :attr:`Response.encoding <requests.Response.encoding>`388property, or use the raw :attr:`Response.content <requests.Response.content>`.389390HTTP Verbs391----------392
18 unmodified lines
411 ... print r.headers['content-type']412 ...413 application/json; charset=utf-8414409So, GitHub returns JSON. That's great, we can use the ``r.json`` method to410parse it into Python objects.415So, GitHub returns JSON. That's great, we can use the :meth:`r.json416<requests.Response.json>` method to parse it into Python objects.417418::419420 >>> commit_data = r.json()
167 unmodified lines
588`described here`_. Transport Adapters provide a mechanism to define interaction589methods for an HTTP service. In particular, they allow you to apply per-service590configuration.591586Requests ships with a single Transport Adapter, the587:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`. This adapter provides the588default Requests interaction with HTTP and HTTPS using the powerful `urllib3`_589library. Whenever a Requests :class:`Session <Session>` is initialized, one of590these is attached to the :class:`Session <Session>` object for HTTP, and one592Requests ships with a single Transport Adapter, the :class:`HTTPAdapter593<requests.adapters.HTTPAdapter>`. This adapter provides the default Requests594interaction with HTTP and HTTPS using the powerful `urllib3`_ library. Whenever595a Requests :class:`Session <requests.Session>` is initialized, one of these is596attached to the :class:`Session <requests.Session>` object for HTTP, and one597for HTTPS.598599Requests enables users to create and use their own Transport Adapters that600provide specific functionality. Once created, a Transport Adapter can be
9 unmodified lines
610prefix. Once mounted, any HTTP request made using that session whose URL starts611with the given prefix will use the given Transport Adapter.612613Implementing a Transport Adapter is beyond the scope of this documentation, but608a good start would be to subclass the ``requests.adapters.BaseAdapter`` class.614a good start would be to subclass the :class:`requests.adapters.BaseAdapter` class.615616.. _`described here`: http://kennethreitz.org/exposures/the-future-of-python-http617.. _`urllib3`: https://github.com/shazow/urllib3618619Blocking Or Non-Blocking?620-------------------------621622With the default Transport Adapter in place, Requests does not provide any kind617of non-blocking IO. The ``Response.content`` property will block until the618entire response has been downloaded. If you require more granularity, the619streaming features of the library (see :ref:`streaming-requests`) allow you to620retrieve smaller quantities of the response at a time. However, these calls621will still block.623of non-blocking IO. The :attr:`Response.content <requests.Response.content>`624property will block until the entire response has been downloaded. If625you require more granularity, the streaming features of the library (see626:ref:`streaming-requests`) allow you to retrieve smaller quantities of the627response at a time. However, these calls will still block.628629If you are concerned about the use of blocking IO, there are lots of projects630out there that combine Requests with one of Python's asynchronicity frameworks.631Two excellent examples are `grequests`_ and `requests-futures`_.
3 unmodified lines
modified:docs/conf.py+6 added-1 removed
25 unmodified lines
26#needs_sphinx = '1.0'2728# Add any Sphinx extension module names here, as strings. They can be extensions29# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.30extensions = ['sphinx.ext.autodoc']30extensions = [31 'sphinx.ext.autodoc',32 'sphinx.ext.intersphinx',33]3435# Add any paths that contain templates here, relative to this directory.36templates_path = ['_templates']37
205 unmodified lines
243244sys.path.append(os.path.abspath('_themes'))245html_theme_path = ['_themes']246html_theme = 'kr'247248intersphinx_mapping = {'urllib3': ('http://urllib3.readthedocs.org/en/latest', None)}