catch TooManyRedirects in safe_mode
authormiguel <miguel@immunityinc.com>
Fri, 3 Feb 2012 19:16:23 +0000 (14:16 -0500)
committerShivaram Lingamneni <slingamn@cs.stanford.edu>
Wed, 2 May 2012 00:00:19 +0000 (17:00 -0700)
requests/models.py

index c11858b..be6a4ed 100644 (file)
@@ -631,7 +631,15 @@ class Request(object):
                 else:
                     raise
 
-            self._build_response(r)
+            # build_response can throw TooManyRedirects
+            try:
+                self._build_response(r)
+            except RequestException as e:
+                if self.config.get('safe_mode', False):
+                    # In safe mode, catch the exception
+                    self.response.error = e
+                else:
+                    raise
 
             # Response manipulation hook.
             self.response = dispatch_hook('response', self.hooks, self.response)