From 5296b8be90cb79f0e2b36bbf9a6108e65bec0e23 Mon Sep 17 00:00:00 2001 From: Victoria Mo Date: Sat, 14 Jul 2012 16:09:13 -0400 Subject: [PATCH] Fix infinite loop on wrong Digest Authentication (Issue #547) Modified code to use the current fix versus the old fix, which was broken. Co-Authored By: Timnit Gebru Co-Authored By: Sarah Gonzalez Co-Authored By: Leila Muhtasib --- requests/auth.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/requests/auth.py b/requests/auth.py index 0f98d28e..5a196cb0 100644 --- a/requests/auth.py +++ b/requests/auth.py @@ -133,11 +133,11 @@ class HTTPDigestAuth(AuthBase): def handle_401(self, r): """Takes the given response and tries digest-auth, if needed.""" - r.request.deregister_hook('response', self.handle_401) - + num_401_calls = r.request.hooks['response'].count(self.handle_401) + s_auth = r.headers.get('www-authenticate', '') - if 'digest' in s_auth.lower(): + if 'digest' in s_auth.lower() and num_401_calls < 2: last_nonce = '' nonce_count = 0