Issue 1378679: urllib2.HTTPBasicAuthHandler fails on non-default port (original) (raw)

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. given should be protected by the basic authentication.

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