httplib.InvalidURL: nonnumeric port: For characters in the proxypassword in URL

Phoe6 orsenthil at
Mon Nov 13 14:07:38 CET 2006

Fredrik Lundh wrote:

Hi Fredrik,
               I apologize if I offended you or have shown any
impatience. I shall try again:

> oh, please.  urllib.quote is a *function*; there's no way that calling that function
> from code written for urllib2 will affect anything.
> but you can access urllib.quote from the urllib2 namespace too.  it's actually the
> very same function:
> >>> urllib.quote
> <function quote at 0x00F430F0>
> >>> urllib2.quote
> <function quote at 0x00F430F0>
> (urllib2 imports lots of stuff from urllib)

I dont know, it does not for me.

>>> urladd = "|\/|pr0c"
>>> print urladd|\/|pr0c
>>>import urllib2
>>> url = urllib2.quote(urladd)
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
AttributeError: 'module' object has no attribute 'quote'
>>> import urllib
>>> url = urllib.quote(urladd)
>>> print url

> > I dont want to import urllib, with the urllib2 itself wanted to work
> > around this piece of code.
> not wanting to solve a problem is a pretty lousy problem-solving strategy, really.

Sorry. :-) I shall take your advice and try to get to bottom of this
- To the piece of code, I import urllib
- use urllib.quote() to covert the proxy url to a quoted one.
and try again, I get an error:

Traceback (most recent call last):
  File "C:\Python24\forge\ngwallp\", line 38, 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 573, in <lambda>
    lambda r, proxy=url, type=type, meth=self.proxy_open: \
  File "C:\Python24\lib\", line 580, in proxy_open
    if '@' in host:
TypeError: iterable argument required

This is where, I gave up and wrote the previous email as not to mess up
urllib with urllib2.
The piece of code, was working properly till I changed my proxy
password to something containng '|\/|'.
- Before shooting a mail to the grooups, i kindda encoded password to
valid url characters ( %7C%5C/%7C) and tried. But this did not work.
So, I dont think this is urllib.quote() issue. I am looking for a way
as how to use the ProxyHandler with authentication in different way
than I have used below.

proxy_url_add = r'http://' + proxy_user + ':' + proxy_password + '@' +
proxy_url = urllib.quote(proxy_url_add)

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

Thanks for your response.

More information about the Python-list mailing list