From 162b751f6db97c1c3ae4fea4af4d75f89b2ec698 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Tue, 21 Jun 2011 22:40:27 -0400 Subject: [PATCH] Timeouts are normal errors now. -- BREAK ALL TEH TESTS! --- requests/models.py | 10 +++++----- test_requests.py | 7 ++++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/requests/models.py b/requests/models.py index 41108cf3..099f1c66 100644 --- a/requests/models.py +++ b/requests/models.py @@ -296,15 +296,15 @@ class Request(object): if self.cookiejar is not None: self.cookiejar.extract_cookies(resp, req) - except urllib2.HTTPError, why: + except (urllib2.HTTPError, urllib2.URLError), why: + if hasattr(why, 'reason'): + if isinstance(why.reason, socket.timeout): + why = Timeout(why) + self._build_response(why) if not self.redirect: self.response.error = why - # TODO: Support urllib connection refused errors - - except urllib2.URLError, error: - raise Timeout if isinstance(error.reason, socket.timeout) else error else: self._build_response(resp) self.response.ok = True diff --git a/test_requests.py b/test_requests.py index aa2577dd..848297e4 100755 --- a/test_requests.py +++ b/test_requests.py @@ -246,8 +246,13 @@ class RequestsTestSuite(unittest.TestCase): def test_settings(self): + + def test(): + r = requests.get(httpbin('')) + r.raise_for_status() + with requests.settings(timeout=0.0000001): - self.assertRaises(requests.Timeout, requests.get, httpbin('')) + self.assertRaises(requests.Timeout, test) with requests.settings(timeout=100): requests.get(httpbin(''))