Skip to content
Myr

Merge pull request #1695 from sigmavirus24/docs

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

Add bit to docs about iter_content

authored by Cory Benfield · committed by Cory Benfield · parents e91ee0e, 6a24eb6 · Browse files · 1 file+12 added−0 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+12 added−0 removed

  • other:+12 added−0 removed

1 file+12 added−0 removed

modified:docs/user/quickstart.rst+12 added
150 unmodified lines
151 <requests.packages.urllib3.response.HTTPResponse object at 0x101194810>152 >>> r.raw.read(10)153 '\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03'154155In general, however, you should use a pattern like this to save what is being 156streamed to a file::157158 with open(filename, 'wb') as fd:159 for chunk in r.iter_content(chunk_size):160 fd.write(chunk)161162Using ``Response.iter_content`` will handle a lot of what you would otherwise 163have to handle when using ``Response.raw`` directly. When streaming a 164download, the above is the preferred and recommended way to retrieve the 165content.166167168Custom Headers169--------------170171If you'd like to add HTTP headers to a request, simply pass in a ``dict`` to the
259 unmodified lines