Update docs to highlight the value of r.encoding.
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 e0ba49e · Browse files · 2 files·+15 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+15 added−5 removed
- other:+15 added−5 removed
Provenance
- Commit
4a6a0c3- Tree
4004695- Author
Cory Benfield <lukasaoz@gmail.com>- Committer
Cory Benfield <lukasaoz@gmail.com>- Parent
e0ba49e
2 files changed+15 added−5 removed
modified:docs/user/quickstart.rst+10 added-5 removed
97 unmodified lines98 'utf-8'99 >>> r.encoding = 'ISO-8859-1'100 101 If you change the encoding, Requests will use the new value of ``r.encoding``102-whenever you call ``r.text``.102+whenever you call ``r.text``. You might want to do this in any situation where103+you can apply special logic to work out what the encoding of the content will104+be. For example, HTTP and XML have the ability to specify their encoding in105+their body. In situations like this, you should use ``r.content`` to find the106+encoding, and then set ``r.encoding``. This will let you use ``r.text`` with107+the correct encoding.108 109 Requests will also use custom encodings in the event that you need them. If110 you have created your own encoding and registered it with the ``codecs``111 module, you can simply use the codec name as the value of ``r.encoding`` and44 unmodified lines156 <requests.packages.urllib3.response.HTTPResponse object at 0x101194810>157 >>> r.raw.read(10)158 '\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03'159 155-In general, however, you should use a pattern like this to save what is being 160+In general, however, you should use a pattern like this to save what is being161 streamed to a file::162 163 with open(filename, 'wb') as fd:164 for chunk in r.iter_content(chunk_size):165 fd.write(chunk)166 162-Using ``Response.iter_content`` will handle a lot of what you would otherwise 163-have to handle when using ``Response.raw`` directly. When streaming a 164-download, the above is the preferred and recommended way to retrieve the 167+Using ``Response.iter_content`` will handle a lot of what you would otherwise168+have to handle when using ``Response.raw`` directly. When streaming a169+download, the above is the preferred and recommended way to retrieve the170 content.171 172 173 Custom Headers262 unmodified linesmodified:requests/models.py+5 added
690 unmodified lines691 """Content of the response, in unicode.692 693 If Response.encoding is None, encoding will be guessed using694 ``chardet``.695+696+ The encoding of the response content is determined based soley on HTTP697+ headers, following RFC 2616 to the letter. If you can take advantage of698+ non-HTTP knowledge to make a better guess at the encoding, you should699+ set ``r.encoding`` appropriately before accessing this property.700 """701 702 # Try charset from content-type703 content = None78 unmodified lines