Handle too many redirects.
authorJérémy Bethmont <jeremy.bethmont@gmail.com>
Tue, 9 Aug 2011 15:28:58 +0000 (17:28 +0200)
committerJérémy Bethmont <jeremy.bethmont@gmail.com>
Tue, 9 Aug 2011 15:28:58 +0000 (17:28 +0200)
requests/exceptions.py
requests/models.py

index eff7512a9f64d945266986685ebdbbc46dc6467d..c08c61480b307a3d67650c92b83986fcde0adeed 100644 (file)
@@ -21,3 +21,6 @@ class URLRequired(RequestException):
 
 class InvalidMethod(RequestException):
     """An inappropriate method was attempted."""
+
+class TooManyRedirects(RequestException):
+    """Too many redirects."""
index ca72802fe73fc10baf5dd79ec328decb27efcaa8..e08bce25ec247cf9142da99301c83fb6a7246e1e 100644 (file)
@@ -20,7 +20,7 @@ from .monkeys import Request as _Request, HTTPBasicAuthHandler, HTTPForcedBasicA
 from .structures import CaseInsensitiveDict
 from .packages.poster.encode import multipart_encode
 from .packages.poster.streaminghttp import register_openers, get_handlers
-from .exceptions import RequestException, AuthenticationError, Timeout, URLRequired, InvalidMethod
+from .exceptions import RequestException, AuthenticationError, Timeout, URLRequired, InvalidMethod, TooManyRedirects
 
 
 REDIRECT_STATI = (301, 302, 303, 307)
@@ -192,6 +192,9 @@ class Request(object):
                 (self.allow_redirects))
             ):
 
+                if not len(history) < 30:
+                    raise TooManyRedirects()
+
                 history.append(r)
 
                 url = r.headers['location']