httplib.InvalidURL: nonnumeric port: For characters in the proxy password in URL

Phoe6 orsenthil at
Mon Nov 13 09:56:51 CET 2006

     The following piece of code works properly when my proxy password
contains characters[a-zA-Z0-9] etc. But when my proxy password
contained something like '|\/|' , the httplib incorrectly indentified
it as separator. How do I resolve this issue.

# Proxy Address

# Trying with linear way

proxy_user = 'user_name'

# Setup the Proxy with urllib2

proxy_url = 'http://' + proxy_user + ':' + proxy_password + '@' +
proxy_support = urllib2.ProxyHandler({"http":proxy_url})
opener = urllib2.build_opener(proxy_support,urllib2.HTTPHandler)


I get the Error:

Traceback (most recent call last):
  File "C:\Python24\forge\ngwallp\", line 35, in ?
    data = urllib2.urlopen(site)
  File "C:\Python24\lib\", line 130, in urlopen
    return, data)
  File "C:\Python24\lib\", line 358, in open
    response = self._open(req, data)
  File "C:\Python24\lib\", line 376, in _open
    '_open', req)
  File "C:\Python24\lib\", line 337, in _call_chain
    result = func(*args)
  File "C:\Python24\lib\", line 1021, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "C:\Python24\lib\", line 980, in do_open
    h = http_class(host) # will parse host:port
  File "C:\Python24\lib\", line 586, in __init__
    self._set_hostport(host, port)
  File "C:\Python24\lib\", line 598, in _set_hostport
    raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
httplib.InvalidURL: nonnumeric port: '|\'


More information about the Python-list mailing list