From c28da22e9c42e22b303bb07da434ce65e10c0cb2 Mon Sep 17 00:00:00 2001 From: Yossi Gottlieb Date: Sat, 27 Sep 2014 20:42:58 +0300 Subject: [PATCH] A fix for #1979 repeat HTTP digest authentication after redirect. --- requests/auth.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/requests/auth.py b/requests/auth.py index 9b6426d..41be982 100644 --- a/requests/auth.py +++ b/requests/auth.py @@ -150,6 +150,14 @@ class HTTPDigestAuth(AuthBase): return 'Digest %s' % (base) + def handle_302(self, r, **kwargs): + """Reset num_401_calls counter on redirects.""" + try: + delattr(self, 'num_401_calls') + except AttributeError: + pass + return r + def handle_401(self, r, **kwargs): """Takes the given response and tries digest-auth, if needed.""" @@ -194,4 +202,5 @@ class HTTPDigestAuth(AuthBase): except AttributeError: pass r.register_hook('response', self.handle_401) + r.register_hook('response', self.handle_302) return r -- 2.34.1