diff options
author | Andrey Petrov <shazow@gmail.com> | 2015-03-14 14:55:55 -0700 |
---|---|---|
committer | Andrey Petrov <shazow@gmail.com> | 2015-03-14 14:55:55 -0700 |
commit | 941f65f810ce9c3d0dcbb17662e01b4264758ac0 (patch) | |
tree | 870269753606bda5ba5b3cc805e9e39abd54a183 /docs | |
parent | 9f425db689f99016a016f50ea2bd4de336942820 (diff) | |
download | urllib3-941f65f810ce9c3d0dcbb17662e01b4264758ac0.tar.gz |
Simplified stream docs example.
Cc: #560
Diffstat (limited to 'docs')
-rw-r--r-- | docs/index.rst | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/docs/index.rst b/docs/index.rst index 15310bf3..cfff81f4 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -266,25 +266,25 @@ You may also stream your response and get data as they come (e.g. when using :: - >>> import urllib3, datetime + >>> from urllib3 import PoolManager >>> http = urllib3.PoolManager() - >>> # https://gist.github.com/josiahcarlson/3250376 - >>> # server which responds with chunked encoding responses and - >>> # generates chunks every second - >>> r = http.request("GET", "http://localhost:8080/") - + >>> r = http.request("GET", "http://httpbin.org/stream/3") >>> r.getheader("transfer-encoding") 'chunked' - >>> for chunk in http.request("GET", "http://localhost:8080/").stream(): - print "[%s] %s" % (datetime.datetime.now().strftime("%H:%M:%S.%f"), chunk) - [10:57:35.650812] this is chunk: 0 - [10:57:36.652022] this is chunk: 1 - [10:57:37.653238] this is chunk: 2 - [10:57:38.654431] this is chunk: 3 - [10:57:39.655601] this is chunk: 4 - + >>> for chunk in r.stream(): + ... print chunk + {"url": "http://httpbin.org/stream/3", ..., "id": 0, ...} + {"url": "http://httpbin.org/stream/3", ..., "id": 1, ...} + {"url": "http://httpbin.org/stream/3", ..., "id": 2, ...} + >>> r.closed + True + +Completely consuming the stream will auto-close the response and release +the connection back to the pool. If you're only partially consuming the +consuming a stream, make sure to manually call ``r.close()`` on the +response. Foundation ---------- |