minor update to make counting variable totally independent of the urllib2's self.retried

This commit is contained in:
Miroslav Stampar 2011-03-02 10:42:17 +00:00
parent a010386a23
commit 3a1f5744be

View File

@ -17,6 +17,7 @@ class SmartHTTPBasicAuthHandler(urllib2.HTTPBasicAuthHandler):
def __init__(self, *args, **kwargs):
urllib2.HTTPBasicAuthHandler.__init__(self, *args, **kwargs)
self.retried_req = set()
self.retried_count = 0
def reset_retry_count(self):
# Python 2.6.5 will call this on 401 or 407 errors and thus loop
@ -28,13 +29,13 @@ class SmartHTTPBasicAuthHandler(urllib2.HTTPBasicAuthHandler):
# Reset the retry counter once for each request.
if hash(req) not in self.retried_req:
self.retried_req.add(hash(req))
self.retried = 0
self.retried_count = 0
else:
if self.retried > 5:
if self.retried_count > 5:
raise urllib2.HTTPError(req.get_full_url(), 401, "basic auth failed",
headers, None)
else:
self.retried += 1
self.retried_count += 1
return urllib2.HTTPBasicAuthHandler.http_error_auth_reqed(
self, auth_header, host, req, headers)