]> granicus.if.org Git - python/commitdiff
Merged revisions 81638 via svnmerge from
authorSenthil Kumaran <orsenthil@gmail.com>
Tue, 1 Jun 2010 12:56:17 +0000 (12:56 +0000)
committerSenthil Kumaran <orsenthil@gmail.com>
Tue, 1 Jun 2010 12:56:17 +0000 (12:56 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

................
  r81638 | senthil.kumaran | 2010-06-01 18:23:48 +0530 (Tue, 01 Jun 2010) | 9 lines

  Merged revisions 81636 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk

  ........
    r81636 | senthil.kumaran | 2010-06-01 18:10:07 +0530 (Tue, 01 Jun 2010) | 3 lines

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

Lib/test/test_urllib2.py
Lib/urllib/request.py

index 2da3befe65f636b58249bd1f7ca054fff769e054..9071f4989e0faa3d8f44679bc99d756cc253b931 100644 (file)
@@ -1156,7 +1156,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):
index 5440efb905420cbc35832164384c097f45658a99..95e8e3355775971e373ec6bf71d597d993a8e17c 100644 (file)
@@ -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: