urllib.urlopen("file://...") fails
Seth Delackner
seth at jtan.com
Thu Apr 25 02:31:11 EDT 2002
With python 2.2 on windows, with the file t:\tmp\package.html existing,
>>> import urllib
>>> u = urllib.urlopen("file://t:/tmp/package.html")
Fails with the error below, but "file:t:/tmp/package.html" works. Is
that even a valid url?
>>> u = urllib.urlopen("file:///t:/tmp/package.html")
Traceback (most recent call last):
File "<pyshell#40>", line 1, in ?
u = urllib.urlopen("file:///t:/tmp/package.html")
File "d:\python\lib\urllib.py", line 73, in urlopen
return _urlopener.open(url)
File "d:\python\lib\urllib.py", line 178, in open
return getattr(self, name)(url)
File "d:\python\lib\urllib.py", line 405, in open_file
return self.open_local_file(url)
File "d:\python\lib\urllib.py", line 412, in open_local_file
stats = os.stat(localname)
OSError: [Errno 2] No such file or directory: '\\t:\\tmp\\package.html'
>>> u = urllib.urlopen("file:t:/tmp/package.html")
>>> u.read()
contents of the html file spew forth.
Just for fun I tried localhost instead of just "///":
>>> u = urllib.urlopen("file://localhost/t:/tmp/package.html")
Traceback (most recent call last):
File "<pyshell#41>", line 1, in ?
u = urllib.urlopen("file://localhost/t:/tmp/package.html")
File "d:\python\lib\urllib.py", line 73, in urlopen
return _urlopener.open(url)
File "d:\python\lib\urllib.py", line 178, in open
return getattr(self, name)(url)
File "d:\python\lib\urllib.py", line 403, in open_file
return self.open_ftp(url)
File "d:\python\lib\urllib.py", line 470, in open_ftp
self.ftpcache[key] = \
File "d:\python\lib\urllib.py", line 702, in __init__
self.init()
File "d:\python\lib\urllib.py", line 708, in init
self.ftp.connect(self.host, self.port)
File "D:\PYTHON\lib\ftplib.py", line 131, in connect
raise socket.error, msg
IOError: [Errno ftp error] (10061, 'Connection refused')
More information about the Python-list
mailing list