From: cjstapleton Date: Fri, 28 Feb 2014 16:08:57 +0000 (-0600) Subject: Add timeout to stream with testing X-Git-Tag: v2.3.0~6^2~4^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=930f03c8649613da9efb7915e17428dd1e8526af;p=services%2Fpython-requests.git Add timeout to stream with testing Fixes Issue #1803 --- diff --git a/requests/adapters.py b/requests/adapters.py index ca46223..28bea07 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 3d7cdaa..0fe849d 100755 --- a/test_requests.py +++ b/test_requests.py @@ -1170,6 +1170,15 @@ class TestMorselToCookieMaxAge(unittest.TestCase): with pytest.raises(TypeError): 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() + +