diff options
Diffstat (limited to 'Lib/urllib/request.py')
-rw-r--r-- | Lib/urllib/request.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py index 5440efb..95e8e33 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -775,12 +775,21 @@ class AbstractBasicAuthHandler: password_mgr = HTTPPasswordMgr() self.passwd = password_mgr self.add_password = self.passwd.add_password + 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 # XXX could be multiple headers authreq = headers.get(authreq, None) + + if self.retried > 5: + # retry sending the username:password 5 times before failing. + raise HTTPError(req.get_full_url(), 401, "basic auth failed", + headers, None) + else: + self.retried += 1 + if authreq: mo = AbstractBasicAuthHandler.rx.search(authreq) if mo: |