diff options
author | Senthil Kumaran <orsenthil@gmail.com> | 2010-06-01 12:40:07 (GMT) |
---|---|---|
committer | Senthil Kumaran <orsenthil@gmail.com> | 2010-06-01 12:40:07 (GMT) |
commit | 4f0108b0d9db4f992dd9e34ce899a54631fe6351 (patch) | |
tree | 1cebef0539f04226507de0846c65649ee259dcf4 /Lib | |
parent | b1a14051b7ed66fa25ed1af7f808ed6a515e37fb (diff) | |
download | cpython-4f0108b0d9db4f992dd9e34ce899a54631fe6351.zip cpython-4f0108b0d9db4f992dd9e34ce899a54631fe6351.tar.gz cpython-4f0108b0d9db4f992dd9e34ce899a54631fe6351.tar.bz2 |
Fix Issue8797 - urllib2 basic authentication fix for wrong passwords. It fails after 5 retries.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_urllib2.py | 1 | ||||
-rw-r--r-- | Lib/urllib2.py | 9 |
2 files changed, 9 insertions, 1 deletions
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index 9364b3d..b5a2437 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -1143,7 +1143,6 @@ class HandlerTests(unittest.TestCase): self.assertEqual(len(http_handler.requests), 1) self.assertFalse(http_handler.requests[0].has_header(auth_header)) - class MiscTests(unittest.TestCase): def test_build_opener(self): diff --git a/Lib/urllib2.py b/Lib/urllib2.py index 43ca53d..40e4427 100644 --- a/Lib/urllib2.py +++ b/Lib/urllib2.py @@ -819,12 +819,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: |