[issue23328] urllib2 fails for proxy credentials that contain a '/' character

2015-01-26 Thread Andy Reitz

New submission from Andy Reitz:

On Python 2.7.9, if I set an https_proxy environment variable, where the 
password contains a '/' character, urllib2 fails. Given this test code:

  import os, urllib
  os.environ['http_proxy'] = "http://someuser:a/b@10.11.12.13:1234";
  f = urllib.urlopen('http://www.python.org')
  data = f.read()
  print data

I expect this error message (because my sample proxy is totally bogus):

[areitz@SOMEHOST ~]$ python2.7 test.py
Traceback (most recent call last):
  File "test.py", line 3, in 
f = urllib.urlopen('http://www.python.org')
  File "/usr/lib64/python2.7/urllib.py", line 87, in urlopen
return opener.open(url)
  File "/usr/lib64/python2.7/urllib.py", line 213, in open
return getattr(self, name)(url)
  File "/usr/lib64/python2.7/urllib.py", line 350, in open_http
h.endheaders(data)
  File "/usr/lib64/python2.7/httplib.py", line 997, in endheaders
self._send_output(message_body)
  File "/usr/lib64/python2.7/httplib.py", line 850, in _send_output
self.send(msg)
  File "/usr/lib64/python2.7/httplib.py", line 812, in send
self.connect()
  File "/usr/lib64/python2.7/httplib.py", line 793, in connect
self.timeout, self.source_address)
  File "/usr/lib64/python2.7/socket.py", line 571, in create_connection
raise err
IOError: [Errno socket error] [Errno 101] Network is unreachable

Instead, I receive this error:

[areitz@SOMEHOST ~]$ python2.7 test.py
Traceback (most recent call last):
  File "test.py", line 3, in 
f = urllib.urlopen('http://www.python.org')
  File "/usr/lib64/python2.7/urllib.py", line 87, in urlopen
return opener.open(url)
  File "/usr/lib64/python2.7/urllib.py", line 213, in open
return getattr(self, name)(url)
  File "/usr/lib64/python2.7/urllib.py", line 339, in open_http
h = httplib.HTTP(host)
  File "/usr/lib64/python2.7/httplib.py", line 1107, in __init__
self._setup(self._connection_class(host, port, strict))
  File "/usr/lib64/python2.7/httplib.py", line 712, in __init__
(self.host, self.port) = self._get_hostport(host, port)
  File "/usr/lib64/python2.7/httplib.py", line 754, in _get_hostport
raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
httplib.InvalidURL: nonnumeric port: 'a'

Note that from the error, it seems as if urllib2 is incorrectly parsing the 
password from the proxy URL. When trying this with curl 7.19.7, I see the 
proper behavior (the correct password is parsed from the proxy URL).

--
components: Library (Lib)
messages: 234809
nosy: Andy.Reitz
priority: normal
severity: normal
status: open
title: urllib2 fails for proxy credentials that contain a '/' character
type: behavior
versions: Python 2.7

___
Python tracker 
<http://bugs.python.org/issue23328>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23328] urllib2 fails for proxy credentials that contain a '/' character

2015-01-26 Thread Andy Reitz

Andy Reitz added the comment:

Sorry, went a bit too quickly -- here is the sample code that I meant to use:

  import os, urllib2
  os.environ['http_proxy'] = "http://someuser:a/b@10.11.12.13:1234";
  f = urllib2.urlopen('http://www.python.org')
  data = f.read()
  print data

And the stack trace that I receive:

Traceback (most recent call last):
  File "test.py", line 3, in 
f = urllib2.urlopen('http://www.python.org')
  File "/usr/lib64/python2.7/urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
  File "/usr/lib64/python2.7/urllib2.py", line 431, in open
response = self._open(req, data)
  File "/usr/lib64/python2.7/urllib2.py", line 449, in _open
'_open', req)
  File "/usr/lib64/python2.7/urllib2.py", line 409, in _call_chain
result = func(*args)
  File "/usr/lib64/python2.7/urllib2.py", line 1227, in http_open
return self.do_open(httplib.HTTPConnection, req)
  File "/usr/lib64/python2.7/urllib2.py", line 1166, in do_open
h = http_class(host, timeout=req.timeout, **http_conn_args)
  File "/usr/lib64/python2.7/httplib.py", line 712, in __init__
(self.host, self.port) = self._get_hostport(host, port)
  File "/usr/lib64/python2.7/httplib.py", line 754, in _get_hostport
raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
httplib.InvalidURL: nonnumeric port: 'a'

It actually looks the same -- so I suppose this issue affects both urllib and 
urllib2.

--

___
Python tracker 
<http://bugs.python.org/issue23328>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23328] urllib2 fails for proxy credentials that contain a '/' character

2015-02-08 Thread Andy Reitz

Andy Reitz added the comment:

The proxy credentials are supplied by our sysadmin. My understanding is that 
the http_proxy env variable doesn't require URI encoding. In addition, the same 
credentials work fine with curl.

--

___
Python tracker 
<http://bugs.python.org/issue23328>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23328] urllib2 fails for proxy credentials that contain a '/' character

2015-02-09 Thread Andy Reitz

Andy Reitz added the comment:

Sure, but the question is who should do the encoding -- the user, or python? I 
think it would be better for python to read the password from the environment 
variable, and encode it before using it. I think this is what users expect.

--

___
Python tracker 
<http://bugs.python.org/issue23328>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com