[Patches] [ python-Patches-944110 ] urllib2 authentication mishandles empty pass bugfix 944082

SourceForge.net noreply at sourceforge.net
Wed May 5 21:42:54 EDT 2004


Patches item #944110, was opened at 2004-04-29 02:52
Message generated for change (Comment added) made by loewis
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=944110&group_id=5470

Category: Library (Lib)
Group: None
>Status: Closed
>Resolution: Accepted
Priority: 7
Submitted By: sc0rp (yangir)
Assigned to: Martin v. Löwis (loewis)
Summary: urllib2 authentication mishandles empty pass bugfix 944082

Initial Comment:
If example.org requires authentication, then following 
code:

host = 'example.org'
user = 'testuser'
password = ''
url = 'http://%s/' % host
authInfo = urllib2.HTTPPasswordMgrWithDefaultRealm()
authInfo.add_password( None, host, user, password )
authHandler = urllib2.HTTPBasicAuthHandler( authInfo )
opener = urllib2.build_opener( authHandler )
urlFile = opener.open( url )
print urlFile.read()

will die by throwing HTTPError 401:

  File "/usr/lib/python2.3/urllib2.py", line 419, in 
http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 401: Authorization Required

even if authenticating with 'testuser' and empty 
password is valid.


Empty password is mishandled (i.e. authentication with 
empty password string is ignored) in 
AbstractBasicAuthHandler.retry_http_basic_auth

def retry_http_basic_auth(self, host, req, realm):
    user,pw = self.passwd.find_user_password(realm, 
host)
    if pw: 
    [...]


It can be fixed by changing:
    if pw:
to
    if pw is not None:



Patch attached.


----------------------------------------------------------------------

>Comment By: Martin v. Löwis (loewis)
Date: 2004-05-06 03:42

Message:
Logged In: YES 
user_id=21627

Thanks for the patch. Applied as

urllib2.py 1.53.6.5, 1.65
NEWS 1.831.4.103


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=944110&group_id=5470



More information about the Patches mailing list