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 doesn't handle username/password in url
Type: Stage:
Components: None Versions:
process
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: Nosy List: fresh, georg.brandl, langmead, orsenthil, sjoerd
Priority: normal Keywords:

Created on 2004-04-29 11:04 by fresh, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (6)
msg20637 - (view) Author: Chris Withers (fresh) Date: 2004-04-29 11:04
>>> urllib2.urlopen('http://username:password@server')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "C:\PYTHON23\lib\urllib2.py", line 129, in urlopen
    return _opener.open(url, data)
  File "C:\PYTHON23\lib\urllib2.py", line 326, in open
    '_open', req)
  File "C:\PYTHON23\lib\urllib2.py", line 306, in
_call_chain
    result = func(*args)
  File "C:\PYTHON23\lib\urllib2.py", line 901, in http_open
    return self.do_open(httplib.HTTP, req)
  File "C:\PYTHON23\lib\urllib2.py", line 860, in do_open
    h = http_class(host) # will parse host:port
  File "C:\Python23\lib\httplib.py", line 1009, in __init__
    self._setup(self._connection_class(host, port, strict))
  File "C:\Python23\lib\httplib.py", line 507, in __init__
    self._set_hostport(host, port)
  File "C:\Python23\lib\httplib.py", line 518, in
_set_hostport
    raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
httplib.InvalidURL: nonnumeric port: 'password@server'

cheers,

Chris
msg20638 - (view) Author: Andrew Langmead (langmead) Date: 2004-05-05 20:34
Logged In: YES 
user_id=119306

Although allowing a username and password in the URL is a 
common client extension, it is not part of the standard <http://
rfc.net/rfc1738.html#s3.3.>
msg20639 - (view) Author: Chris Withers (fresh) Date: 2004-05-05 21:01
Logged In: YES 
user_id=24723

However, given that the original urllib supported this, it
is suprising that urllib2 doesn't.
msg20640 - (view) Author: Sjoerd Mullender (sjoerd) * (Python committer) Date: 2004-05-05 21:22
Logged In: YES 
user_id=43607

I don't know (nor care) about RFC 1738, but it's successor
RFC 2396 *does* mention <userinfo>@<host>:<port> as a
possible "server".  See section 3.2.2.  I admit, it also
says that it is not recommended, but it does specifically
allow username + password in the URI.
msg20641 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-02-20 21:00
Logged In: YES 
user_id=849994

This is also reported by #979407.
msg20642 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2006-11-13 14:00
Logged In: YES 
user_id=942711

It does handle:

proxy_user = 'user_name'
proxy_password ='password'

# Setup the Proxy with urllib2

proxy_url = 'http://' + proxy_user + ':' + proxy_password + '@' + PROXY_IP

proxy_support = urllib2.ProxyHandler({"http":proxy_url})
opener = urllib2.build_opener(proxy_support,urllib2.HTTPHandler)
urllib2.install_opener(opener)

Worked properly for me so long.
History
Date User Action Args
2022-04-11 14:56:03adminsetgithub: 40198
2009-02-12 17:42:24ajaksu2linkissue979407 dependencies
2004-04-29 11:04:30freshcreate