Document encodings and RFC compliance.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Cory Benfield · committed by Cory Benfield · parent 40ba6b4 · 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
Provenance
- Commit
7a9419c- Tree
7139f5d- Author
Cory Benfield <lukasaoz@gmail.com>- Committer
Cory Benfield <lukasaoz@gmail.com>- Parent
40ba6b4
2 files changed+40 added−5 removed
modified:docs/user/advanced.rst+25 added
341 unmodified lines342 proxies = {343 "http": "http://user:pass@10.10.1.10:3128/",344 }345 346+Compliance347+----------348 349+Requests is intended to be compliant with all relevant specifications and350+RFCs where that compliance will not cause difficulties for users. This351+attention to the specification can lead to some behaviour that may seem352+unusual to those not familiar with the relevant specification.353+354+Encodings355+^^^^^^^^^356+357+When you receive a response, Requests makes a guess at the encoding to use for358+decoding the response when you call the ``Response.text`` method. Requests359+will first check for an encoding in the HTTP header, and if none is present,360+will use `chardet <http://pypi.python.org/pypi/chardet>`_ to attempt to guess361+the encoding.362+363+The only time Requests will not do this is if no explicit charset is present364+in the HTTP headers **and** the ``Content-Type`` header contains ``text``. In365+this situation,366+`RFC 2616 <http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7.1>`_367+specifies that the default charset must be ``ISO-8859-1``. Requests follows368+the specification in this case. If you require a different encoding, you can369+manually set the ``Response.encoding`` property, or use the raw370+``Request.content``.371+372 HTTP Verbs373 ----------374 375 Requests provides access to almost the full range of HTTP verbs: GET, OPTIONS,151 unmodified linesmodified:docs/user/quickstart.rst+15 added-5 removed
84 unmodified lines85 86 Requests will automatically decode content from the server. Most unicode87 charsets are seamlessly decoded.88 89-When you make a request, ``r.encoding`` is set, based on the HTTP headers.90-Requests will use that encoding when you access ``r.text``. If ``r.encoding``91-is ``None``, Requests will make an extremely educated guess of the encoding92-of the response body. You can manually set ``r.encoding`` to any encoding93-you'd like, and that charset will be used.89+When you make a request, Requests makes educated guesses about the encoding of90+the response based on the HTTP headers. The text encoding guessed by Requests91+is used when you access ``r.text``. You can find out what encoding Requests is92+using, and change it, using the ``r.encoding`` property::93 94+ >>> r.encoding95+ 'utf-8'96+ >>> r.encoding = 'ISO-8859-1'97 98+If you change the encoding, Requests will use the new value of ``r.encoding``99+whenever you call ``r.text``.100+101+Requests will also use custom encodings in the event that you need them. If102+you have created your own encoding and registered it with the ``codecs``103+module, you can simply use the codec name as the value of ``r.encoding`` and104+Requests will handle the decoding for you.105+106 Binary Response Content107 -----------------------108 109 You can also access the response body as bytes, for non-text requests::353 unmodified lines