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.

Author vinay.sajip
Recipients vinay.sajip
Date 2010-05-24.10:23:19
SpamBayes Score 1.033508e-07
Marked as misclassified No
Message-id <1274696603.9.0.49787272885.issue8801@psf.upfronthosting.co.za>
In-reply-to
Content
I encountered what seems like an incompatibility between urllib and urllib2 in the way they handle file:// URLs. Here's a console session to illustrate:

vinay <at> eta-karmic:/tmp$ echo Hello, world! >hello.txt
vinay <at> eta-karmic:/tmp$ cat hello.txt 
Hello, world!
vinay <at> eta-karmic:/tmp$ python
Python 2.6.4 (r264:75706, Dec  7 2009, 18:45:15) 
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib,urllib2
>>> s = 'file:////tmp/hello.txt'
>>> f1 = urllib.urlopen(s)
>>> f1.read()
'Hello, world!\n'
>>> f2 = urllib2.urlopen(s)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/urllib2.py", line 124, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/lib/python2.6/urllib2.py", line 389, in open
    response = self._open(req, data)
  File "/usr/lib/python2.6/urllib2.py", line 407, in _open
    '_open', req)
  File "/usr/lib/python2.6/urllib2.py", line 367, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.6/urllib2.py", line 1240, in file_open
    return self.parent.open(req)
  File "/usr/lib/python2.6/urllib2.py", line 389, in open
    response = self._open(req, data)
  File "/usr/lib/python2.6/urllib2.py", line 407, in _open
    '_open', req)
  File "/usr/lib/python2.6/urllib2.py", line 367, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.6/urllib2.py", line 1287, in ftp_open
    raise URLError('ftp error: no host given')
urllib2.URLError: <urlopen error ftp error: no host given>
>>> 

The problem appears to be that urllib allows a badly-formed file URL (with file://// rather than file:///) when it shouldn't (errors should not pass silently).
History
Date User Action Args
2010-05-24 10:23:23vinay.sajipsetrecipients: + vinay.sajip
2010-05-24 10:23:23vinay.sajipsetmessageid: <1274696603.9.0.49787272885.issue8801@psf.upfronthosting.co.za>
2010-05-24 10:23:21vinay.sajiplinkissue8801 messages
2010-05-24 10:23:19vinay.sajipcreate