This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: urllib2.HTTPBasicAuthHandler fails on non-default port
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, gusarov
Priority: normal Keywords:

Created on 2005-12-12 11:50 by gusarov, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
a.py gusarov, 2005-12-12 12:09 problem code
Messages (3)
msg27050 - (view) Author: Mikhail Gusarov (gusarov) Date: 2005-12-12 11:50
HTTPBasicAuthHandler (or, more precise, 
AbstractBasicAuthHandler) does not work when non-
default port is in use: passwords added to it just not 
being passed back in answer to the 401 error code. 
Default port works fine.

I tracked the problem with it to the HTTPPasswordMgr.
find_user_password: it accepts 'authuri' and reduce it 
using reduce_uri().

AbstractBasicAuthHandler passes as 'authuri' parameter 
just hostname, in form 'myhost:myport' and this cause 
reduce_uri() to parse it as URI with schema 'myhost' 
and netloc 'myport', which is obviously wrong. Passing 
to the reduce_uri() hostname in form 'myhost' works 
fine.

I placed the the program demonstrating the bug to the 
attach: it throws HTTPError in my case. Of course 
change the host, port, user and password to the 
reflecting your setup. <uri> given should be protected 
by the basic authentication.
msg27051 - (view) Author: Mikhail Gusarov (gusarov) Date: 2005-12-12 12:10
Logged In: YES 
user_id=501458

Problem was fixed by changing 

user, pw = self.passwd.find_user_password(realm, host)

to the

    user, pw = self.passwd.find_user_password(realm, req.
get_full_url())

in the problem function

msg27052 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-01-20 22:01
Logged In: YES 
user_id=1188172

Fixed in rev. 42130 in 2.4 branch. Already fixed in HEAD.
History
Date User Action Args
2022-04-11 14:56:14adminsetgithub: 42681
2005-12-12 11:50:03gusarovcreate