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"
|