Red Hat Bugzilla – Bug 669847
urllib2's AbstractBasicAuthHandler is limited to 6 requests
Last modified: 2016-05-31 21:47:17 EDT
Description of problem: See e.g. http://permalink.gmane.org/gmane.comp.python.enthought.devel/27376 This appears to be a regression in python 2.6.6 relative to 2.6.5 Upstream bug report: http://bugs.python.org/issue9639 It is fixed in the upstream 2.7 branch, but was not backported to 2.6 as it's not a security fix: http://svn.python.org/view?view=rev&revision=84207 Version-Release number of selected component (if applicable): python-2.6.6-3.el6.x86_64 How reproducible: 100% Steps to Reproduce: Run the following python code fragment, from the enthought mailing list (which relies on browserspy.dk): ---- BEGIN QUOTE ---- import urllib2 passman = urllib2.HTTPPasswordMgrWithDefaultRealm() passman.add_password(None, 'http://browserspy.dk', 'test', 'test') authhandler = urllib2.HTTPBasicAuthHandler(passman) opener = urllib2.build_opener(authhandler) for i in xrange(10): print "Loop {0}".format(i) pagehandle = opener.open('http://browserspy.dk/password-ok.php') pagehandle.close() ---- END QUOTE ----- Actual results: With 2.6.6, it fails on i == 6 with this output: ---- BEGIN QUOTE ---- Loop 0 Loop 1 Loop 2 Loop 3 Loop 4 Loop 5 Loop 6 Traceback (most recent call last): File "<stdin>", line 3, in <module> File "/usr/lib64/python2.6/urllib2.py", line 397, in open response = meth(req, response) File "/usr/lib64/python2.6/urllib2.py", line 510, in http_response 'http', request, response, code, msg, hdrs) File "/usr/lib64/python2.6/urllib2.py", line 429, in error result = self._call_chain(*args) File "/usr/lib64/python2.6/urllib2.py", line 369, in _call_chain result = func(*args) File "/usr/lib64/python2.6/urllib2.py", line 864, in http_error_401 url, req, headers) File "/usr/lib64/python2.6/urllib2.py", line 833, in http_error_auth_reqed headers, None) urllib2.HTTPError: HTTP Error 401: basic auth failed ---- END QUOTE ----- Expected results: With python-2.6.5-9.fc14.x86_64, it successfully runs 10 iterations: ---- BEGIN QUOTE ---- Loop 0 Loop 1 Loop 2 Loop 3 Loop 4 Loop 5 Loop 6 Loop 7 Loop 8 Loop 9 ---- END QUOTE ----- (See also bug 649274)
Technical note added. If any revisions are required, please edit the "Technical Notes" field accordingly. All revisions will be proofread by the Engineering Content Services team. New Contents: Basic HTTP authentication via the urllib2 module was limited to six requests because the "retried" attribute was not reset when authentication was successful. This attribute is now reset, and authentication requests work as expected.
An advisory has been issued which should help the problem described in this bug report. This report is therefore being closed with a resolution of ERRATA. For more information on therefore solution and/or where to find the updated files, please follow the link below. You may reopen this bug report if the solution does not work for you. http://rhn.redhat.com/errata/RHSA-2011-0554.html