From: Senthil Kumaran Date: Thu, 19 Aug 2010 17:32:03 +0000 (+0000) Subject: Fix - Issue9639: Reset the retry counter after successful authentication. X-Git-Tag: v2.7.1rc1~386 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4f1ba0de8afe4a5055d7b3dd81a952fe17c226d6;p=python Fix - Issue9639: Reset the retry counter after successful authentication. --- diff --git a/Lib/urllib2.py b/Lib/urllib2.py index 7af882cb38..08217613eb 100644 --- a/Lib/urllib2.py +++ b/Lib/urllib2.py @@ -822,6 +822,9 @@ class AbstractBasicAuthHandler: self.add_password = self.passwd.add_password self.retried = 0 + def reset_retry_count(self): + self.retried = 0 + def http_error_auth_reqed(self, authreq, host, req, headers): # host may be an authority (without userinfo) or a URL with an # authority @@ -861,8 +864,10 @@ class HTTPBasicAuthHandler(AbstractBasicAuthHandler, BaseHandler): def http_error_401(self, req, fp, code, msg, headers): url = req.get_full_url() - return self.http_error_auth_reqed('www-authenticate', - url, req, headers) + response = self.http_error_auth_reqed('www-authenticate', + url, req, headers) + self.reset_retry_count() + return response class ProxyBasicAuthHandler(AbstractBasicAuthHandler, BaseHandler): @@ -875,8 +880,10 @@ class ProxyBasicAuthHandler(AbstractBasicAuthHandler, BaseHandler): # should not, RFC 3986 s. 3.2.1) support requests for URLs containing # userinfo. authority = req.get_host() - return self.http_error_auth_reqed('proxy-authenticate', + response = self.http_error_auth_reqed('proxy-authenticate', authority, req, headers) + self.reset_retry_count() + return response def randombytes(n):