[ python-Bugs-820583 ] urllib2 silently returns None when auth_uri is mismatched

SourceForge.net noreply at sourceforge.net
Sun Nov 30 17:18:47 EST 2003


Bugs item #820583, was opened at 2003-10-09 13:11
Message generated for change (Comment added) made by jjlee
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=820583&group_id=5470

Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Christopher Armstrong (radeex)
Assigned to: Nobody/Anonymous (nobody)
Summary: urllib2 silently returns None when auth_uri is mismatched

Initial Comment:
Code like the following, where the `uri' argument which
I pass to add_password is not actually the URI that the
web server gives me in its request for basic auth,
makes the return value of OpenDirector.open None. This
is either a code bug or a documentation bug. I expected
director.open to raise an error, but saying something
like "open will return None in these cases: ...." would
also be a valid solution, if one that's not as good,
IMO... the AuthHandler could raise an error once it
realizes that none of the URIs we have match, perhaps?

import urllib2

realm = "Linksys BEFW11S4 V4"

passman = urllib2.HTTPPasswordMgr()
passman.add_password(realm,
'NOT_WHAT_THE_SERVER_GIVES_ME', 'user', 'password')

auther = urllib2.HTTPBasicAuthHandler(passman)
getter = urllib2.HTTPHandler()

director = urllib2.OpenerDirector()

director.add_handler(auther)
director.add_handler(getter)


f = director.open('http://192.168.1.1/Status.htm')
print f, "is None"


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

Comment By: John J Lee (jjlee)
Date: 2003-11-30 22:18

Message:
Logged In: YES 
user_id=261020

Uploaded doc fix as patch 851752. 

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

Comment By: John J Lee (jjlee)
Date: 2003-10-29 23:56

Message:
Logged In: YES 
user_id=261020

It's a doc bug.  I'll add a doc patch later. 
 
Returning None from a handler means "I can't handle this, but 
another handler might".  So AuthHandler is correct to return 
None, and shouldn't raise an exception.  If you want to get a 
URLError in cases where all relevant handlers return None, 
you need to do: 
 
director.add_handler(UnknownHandler) 
 
(which build_opener will do for you, actually) 

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

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



More information about the Python-bugs-list mailing list