Timeouts are normal errors now.
authorKenneth Reitz <me@kennethreitz.com>
Wed, 22 Jun 2011 02:40:27 +0000 (22:40 -0400)
committerKenneth Reitz <me@kennethreitz.com>
Wed, 22 Jun 2011 02:40:27 +0000 (22:40 -0400)
--
BREAK ALL TEH TESTS!

requests/models.py
test_requests.py

index 41108cf3ebd7505b8ef1068c3d2bf1fd2d744505..099f1c66c1be25f56060ec35565184ed9d4698ad 100644 (file)
@@ -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
index aa2577dd2a5cf243cadeaf98218642535a591f73..848297e433ea9faaed7b68f3852fb8c6e19086e3 100755 (executable)
@@ -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(''))