summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Reitz <me@kennethreitz.org>2014-03-03 13:14:37 -0500
committerKenneth Reitz <me@kennethreitz.org>2014-03-03 13:14:37 -0500
commitd8557a26270f116824f717a1cd6a6ff2b69e5f6a (patch)
treef8cea0de72b767dccd7c9b2ea19a735a3c99a15b
parent3c4b3747e45318ba8df2224fea13895e5210915f (diff)
parent5f404a0592bba18c5eae7b2aead033f3d0cb27ff (diff)
downloadpython-requests-d8557a26270f116824f717a1cd6a6ff2b69e5f6a.tar.gz
Merge pull request #1935 from cjstapleton/master
Add timeout to stream with testing
-rw-r--r--requests/adapters.py5
-rwxr-xr-xtest_requests.py8
2 files changed, 9 insertions, 4 deletions
diff --git a/requests/adapters.py b/requests/adapters.py
index ca462232..28bea07c 100644
--- a/requests/adapters.py
+++ b/requests/adapters.py
@@ -310,10 +310,7 @@ class HTTPAdapter(BaseAdapter):
chunked = not (request.body is None or 'Content-Length' in request.headers)
- if stream:
- timeout = TimeoutSauce(connect=timeout)
- else:
- timeout = TimeoutSauce(connect=timeout, read=timeout)
+ timeout = TimeoutSauce(connect=timeout, read=timeout)
try:
if not chunked:
diff --git a/test_requests.py b/test_requests.py
index 998f17f3..17de8491 100755
--- a/test_requests.py
+++ b/test_requests.py
@@ -1179,5 +1179,13 @@ class TestMorselToCookieMaxAge(unittest.TestCase):
morsel_to_cookie(morsel)
+class TestTimeout:
+ def test_stream_timeout(self):
+ try:
+ r = requests.get('https://httpbin.org/delay/10', timeout=5.0)
+ except requests.exceptions.Timeout as e:
+ assert 'Read timed out' in e.args[0].args[0]
+
+
if __name__ == '__main__':
unittest.main()