Commit 4f0108b0 authored by Senthil Kumaran's avatar Senthil Kumaran

Fix Issue8797 - urllib2 basic authentication fix for wrong passwords. It fails after 5 retries.

parent b1a14051
...@@ -1143,7 +1143,6 @@ class HandlerTests(unittest.TestCase): ...@@ -1143,7 +1143,6 @@ class HandlerTests(unittest.TestCase):
self.assertEqual(len(http_handler.requests), 1) self.assertEqual(len(http_handler.requests), 1)
self.assertFalse(http_handler.requests[0].has_header(auth_header)) self.assertFalse(http_handler.requests[0].has_header(auth_header))
class MiscTests(unittest.TestCase): class MiscTests(unittest.TestCase):
def test_build_opener(self): def test_build_opener(self):
......
...@@ -819,12 +819,21 @@ class AbstractBasicAuthHandler: ...@@ -819,12 +819,21 @@ class AbstractBasicAuthHandler:
password_mgr = HTTPPasswordMgr() password_mgr = HTTPPasswordMgr()
self.passwd = password_mgr self.passwd = password_mgr
self.add_password = self.passwd.add_password self.add_password = self.passwd.add_password
self.retried = 0
def http_error_auth_reqed(self, authreq, host, req, headers): def http_error_auth_reqed(self, authreq, host, req, headers):
# host may be an authority (without userinfo) or a URL with an # host may be an authority (without userinfo) or a URL with an
# authority # authority
# XXX could be multiple headers # XXX could be multiple headers
authreq = headers.get(authreq, None) 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: if authreq:
mo = AbstractBasicAuthHandler.rx.search(authreq) mo = AbstractBasicAuthHandler.rx.search(authreq)
if mo: if mo:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment