From: Ian Cordasco Date: Sun, 20 Oct 2013 17:29:43 +0000 (-0500) Subject: Add bit to docs about iter_content X-Git-Tag: v2.0.1~10^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6a24eb6d20c6747669ecd6d8bda3924a384d4648;p=services%2Fpython-requests.git Add bit to docs about iter_content --- diff --git a/docs/user/quickstart.rst b/docs/user/quickstart.rst index 4313ac2..cd1a5ea 100644 --- a/docs/user/quickstart.rst +++ b/docs/user/quickstart.rst @@ -152,6 +152,18 @@ server, you can access ``r.raw``. If you want to do this, make sure you set >>> r.raw.read(10) '\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03' +In general, however, you should use a pattern like this to save what is being +streamed to a file:: + + with open(filename, 'wb') as fd: + for chunk in r.iter_content(chunk_size): + fd.write(chunk) + +Using ``Response.iter_content`` will handle a lot of what you would otherwise +have to handle when using ``Response.raw`` directly. When streaming a +download, the above is the preferred and recommended way to retrieve the +content. + Custom Headers --------------