Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

urllib2 silently returns None when auth_uri is mismatched #39388

Closed
radeex mannequin opened this issue Oct 9, 2003 · 4 comments
Closed

urllib2 silently returns None when auth_uri is mismatched #39388

radeex mannequin opened this issue Oct 9, 2003 · 4 comments
Assignees
Labels
stdlib Python modules in the Lib dir

Comments

@radeex
Copy link
Mannequin

radeex mannequin commented Oct 9, 2003

BPO 820583
Nosy @kbkaiser

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/kbkaiser'
closed_at = <Date 2004-07-11.02:16:08.000>
created_at = <Date 2003-10-09.12:11:59.000>
labels = ['library']
title = 'urllib2 silently returns None when auth_uri is mismatched'
updated_at = <Date 2004-07-11.02:16:08.000>
user = 'https://bugs.python.org/radeex'

bugs.python.org fields:

activity = <Date 2004-07-11.02:16:08.000>
actor = 'kbk'
assignee = 'kbk'
closed = True
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2003-10-09.12:11:59.000>
creator = 'radeex'
dependencies = []
files = []
hgrepos = []
issue_num = 820583
keywords = []
message_count = 4.0
messages = ['18585', '18586', '18587', '18588']
nosy_count = 3.0
nosy_names = ['kbk', 'jjlee', 'radeex']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue820583'
versions = []

@radeex
Copy link
Mannequin Author

radeex mannequin commented Oct 9, 2003

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"

@radeex radeex mannequin closed this as completed Oct 9, 2003
@radeex radeex mannequin assigned kbkaiser Oct 9, 2003
@radeex radeex mannequin added the stdlib Python modules in the Lib dir label Oct 9, 2003
@radeex radeex mannequin closed this as completed Oct 9, 2003
@radeex radeex mannequin assigned kbkaiser Oct 9, 2003
@radeex radeex mannequin added the stdlib Python modules in the Lib dir label Oct 9, 2003
@jjlee
Copy link
Mannequin

jjlee mannequin commented Oct 29, 2003

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)

@jjlee
Copy link
Mannequin

jjlee mannequin commented Nov 30, 2003

Logged In: YES
user_id=261020

Uploaded doc fix as patch 851752.

@kbkaiser
Copy link
Contributor

Logged In: YES
user_id=149084

patch 851752 applied

liburllib2.tex 1.20

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir
Projects
None yet
Development

No branches or pull requests

1 participant