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 authentication problem #37910
Comments
I've found a problem using the authentication in urllib2. When matching up host-names in order to find a I create a HTTPBasicAuthHandler with a I then setup the proxy to use When I connect, the password lookup fails, because it This problem doesn't exist if I pass There seems to be some stuff in HTTPPasswordMgr to deal Version Info: |
Logged In: YES Can you please retry with Python 2.2.2? It seems that a related bug was fixed for 2.2.2: """
|
Logged In: YES Okay, the same problem crops up in Python 2.2.2 running Version Info: Here's the pertinent section of my test file (passwords and # Setup proxy
proxy_handler = ProxyHandler({"http" :
"http://blah.com:17828"})
# Setup authentication
pass_mgr = HTTPPasswordMgrWithDefaultRealm()
for passwd in [ \
(None, "http://blah.com:17828", "foo",
"bar"), \
# (None, "blah.com:17828", "foo",
"bar"), \ # Works if this line is uncommented
(None, "blah.com", "foo", "bar"), \
]:
print("Adding password set (%s, %s, %s, %s)" % passwd)
pass_mgr.add_password(*passwd)
auth_handler = HTTPBasicAuthHandler(pass_mgr)
proxy_auth_handler = ProxyBasicAuthHandler(pass_mgr)
# Now build a new URL opener and install it
opener = build_opener(proxy_handler, proxy_auth_handler,
auth_handler, HTTPHandler)
install_opener(opener)
# Now try to open a file and see what happens
request = Request("http://www.google.com")
try:
remotefile = urlopen(request)
except HTTPError, ex:
print("Unable to download file due to HTTP Error %d
(%s)." % (ex.code, ex.msg))
return |
Logged In: YES The problem seems to be with the port (:17828), not the URL RFC 2617 (top of page 3) says nothing about removing the I guess gazzadee was doing a urlopen with a different |
Logged In: YES This was a while ago, and my memory has faded. I'll try to I think the question was with the way the password manager I am pretty sure that the problem is not to do with the URI If that password set was added, then the password lookup for I'll see if I can set it up on the latest python and get it Just as an explanation, the situation was that I was running |
Logged In: YES Okay, I have attached a file that replicates this problem. If you run it as is (replacing the proxy name and address If you uncomment line 23 (which specifies the password Technical Info:
|
Logged In: YES Thanks!
It seems .reduce_uri() tries to cope with hostnames as well as
absoluteURIs. I don't understand why it wants to do that, but it
fails, because it doesn't anticipate what urlparse does when a
port is present:
>>> urlparse.urlparse("foo.bar.com")
('', '', 'foo.bar.com', '', '', '')
>>> urlparse.urlparse("foo.bar.com:80")
('foo.bar.com', '', '80', '', '', '')
I haven't checked, but I assume it's just incorrect use of
urlparse to pass it a hostname.
Of course, if it's "fixed" to only accept absoluteURIs, it will
break existing code, so I guess it must be fixed for
hostnames. :-((
Also, I think .is_suburi("/foo/spam", "/foo/eggs") should return
False, but returns True, and .http_error_40x() use
req.get_host() when they should be using req.get_full_url()
(from a quick look at RFC 2617). |
Logged In: YES This issue is fixed by patch 1470846. |
Logged In: YES Closing accordingly. |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: