Fix #2207
authorIan Cordasco <graffatcolmingov@gmail.com>
Sun, 7 Sep 2014 17:02:23 +0000 (12:02 -0500)
committerIan Cordasco <graffatcolmingov@gmail.com>
Sun, 7 Sep 2014 17:02:23 +0000 (12:02 -0500)
@Lukasa wrote the fix in #2207

requests/sessions.py

index 334db58eb14db9a19a4c435676aa9a1687781578..023edfbd3195066bddf8dc16b026cefb352e7616 100644 (file)
@@ -134,8 +134,8 @@ class SessionRedirectMixin(object):
                 url = requote_uri(url)
 
             prepared_request.url = to_native_string(url)
-            # cache the url
-            if resp.is_permanent_redirect:
+            # Cache the url, unless it redirects to itself.
+            if resp.is_permanent_redirect and req.url != prepared_request.url:
                 self.redirect_cache[req.url] = prepared_request.url
 
             # http://tools.ietf.org/html/rfc7231#section-6.4.4