Skip to content
Myr

Merge pull request #772 from Lukasa/develop

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

First pass at documenting encodings and RFC compliance.

authored by Kenneth Reitz · committed by Kenneth Reitz · parents 56b01bf, 7a9419c · Browse files · 2 files+40 added−5 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+40 added−5 removed

  • other:+40 added−5 removed

2 files+40 added−5 removed

modified:docs/user/advanced.rst+25 added
341 unmodified lines
342 proxies = {343 "http": "http://user:pass@10.10.1.10:3128/",344 }345346Compliance347----------348349Requests is intended to be compliant with all relevant specifications and350RFCs where that compliance will not cause difficulties for users. This351attention to the specification can lead to some behaviour that may seem352unusual to those not familiar with the relevant specification.353354Encodings355^^^^^^^^^356357When you receive a response, Requests makes a guess at the encoding to use for358decoding the response when you call the ``Response.text`` method. Requests359will first check for an encoding in the HTTP header, and if none is present,360will use `chardet <http://pypi.python.org/pypi/chardet>`_ to attempt to guess361the encoding.362363The only time Requests will not do this is if no explicit charset is present364in the HTTP headers **and** the ``Content-Type`` header contains ``text``. In365this situation,366`RFC 2616 <http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7.1>`_367specifies that the default charset must be ``ISO-8859-1``. Requests follows368the specification in this case. If you require a different encoding, you can369manually set the ``Response.encoding`` property, or use the raw370``Request.content``.371372HTTP Verbs373----------374375Requests provides access to almost the full range of HTTP verbs: GET, OPTIONS,
151 unmodified lines
modified:docs/user/quickstart.rst+15 added-5 removed
84 unmodified lines
8586Requests will automatically decode content from the server. Most unicode87charsets are seamlessly decoded.8889When you make a request, ``r.encoding`` is set, based on the HTTP headers.90Requests will use that encoding when you access ``r.text``. If ``r.encoding``91is ``None``, Requests will make an extremely educated guess of the encoding92of the response body. You can manually set ``r.encoding`` to any encoding93you'd like, and that charset will be used.89When you make a request, Requests makes educated guesses about the encoding of90the 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::9394 >>> r.encoding95 '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.105106Binary Response Content107-----------------------108109You can also access the response body as bytes, for non-text requests::
353 unmodified lines