Skip to content
Myr

explain binary response data

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

authored by Kenneth Reitz · committed by Kenneth Reitz · parent c32b1cd · Browse files · 1 file+32 added−6 removed
This commit

State

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

Diff stats

1 file+32 added−6 removed

  • other:+32 added−6 removed

1 file+32 added−6 removed

modified:docs/user/quickstart.rst+32 added-6 removed
34 unmodified lines
35----------------3637We can read the content of the server's response::3839 >>> r.content39 >>> r.text40 '[{"repository":{"open_issues":0,"url":"https://github.com/...4142Requests does its best to decode content from the server. Most unicode43charsets, ``gzip``, and ``deflate`` encodings are all seamlessly decoded.42Requests will automatically decode content from the server. Most unicode43charsets are seamlessly decoded.4445When you make a request, ``r.encoding`` is set, based on the HTTP headers.46Requests will attempt to use that encoding when you access ``r.content``. You47can manually set ``r.encoding`` to any encoding you'd like (including ``None``),48and that charset will be used.46Requests will use that encoding when you access ``r.text``. If ``r.encoding``47is ``None``, Requests will make an extremely educated guess of the encoding48of the response body. You can manually set ``r.encoding`` to any encoding49you'd like, and that charset will be used.505152Binary Response Content53-----------------------5455You can also access the response body as bytes, for non-text requests::5657 >>> r.content58 b'[{"repository":{"open_issues":0,"url":"https://github.com/...5960The ``gzip`` and ``deflate`` transfer-encodings are automatically decoded for you.616263Raw Response Content64--------------------6566In the rare case that you'd like to get the absolute raw socket response from the server,67you can access ``r.raw``::6869 >>> r.raw70 <requests.packages.urllib3.response.HTTPResponse object at 0x101194810>7172 >>> r.raw.read(10)73 '\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03'74757677Make a POST Request78-------------------7980POST requests are equally simple::
319 unmodified lines