bug in urllib under Window?
dave at rotwang.freeserve.co.uk
Thu Sep 27 13:42:40 CEST 2001
I have found what appears to be a bug in urllib.
urllib.urlopen() has been failing with error 'invalid literal'. It appears
to be confusing an http: protocol with the domain. I've had this problem
with Python 2.0 and 2.1. I seem to remember using urlopen() without problems
before. I suspect that the problem is caused by the data held in the Windows
registry being inconsistent. It may well be that urllib is correct and my
service provider's dialer installer is buggy. I noticed that other people
have come across this problem before.
The traceback is as follows:
File "C:\PROGRAM FILES\PYTHON21\lib\urllib.py", line 71, in urlopen
File "C:\PROGRAM FILES\PYTHON21\lib\urllib.py", line 176, in open
return getattr(self, name)(url)
File "C:\PROGRAM FILES\PYTHON21\lib\urllib.py", line 277, in open_http
h = httplib.HTTP(host)
File "C:\PROGRAM FILES\PYTHON21\lib\httplib.py", line 663, in __init__
self._conn = self._connection_class(host, port)
File "C:\PROGRAM FILES\PYTHON21\lib\httplib.py", line 342, in __init__
File "C:\PROGRAM FILES\PYTHON21\lib\httplib.py", line 348, in
port = int(host[i+1:])
ValueError: invalid literal for int():
The 'host' variable contains the protocol, 'http:', which is clearly wrong.
The code is attempting to strip the port number from it and fails.
I tried debuging the urllib (by putting print statements in it)
urllib.get_proxies() for Win32 returns (for protocol http)
This is clearly wrong. This data is stored in the registry under:
which contains a semicolon delimited list of mappings of protocol to proxy,
in my case:
I tracked the problem down to the Windows specific code that reads data from
the registry, urllib.py line 1270:
proxies[protocol] = '%s://%s' % (protocol, address)'
proxies[protocol] = address
As the address seems to contain the protocol already. Maybe this is a bug
caused by incorrect data being entered in the registry. The protocol
information is clearly duplicated in this example. The code assumes that it
is not present in the url.
Has anyone had any similar experiences with urllib?
More information about the Python-list