On Fri, Jul 9, 2010 at 12:41, Bill Janssen <jans...@parc.com> wrote: > So, FTP is *not* the "default protocol". On the other hand, if <host> > actually begins with "ftp.", it's a pretty good guess that FTP will > work.
Actually, FTP *is* the default protocol for most URLs with hostnames in urllib.py. urllib.open_file() delegates to open_ftp() if there's a any host other than the exact string "localhost", and open_local_file() otherwise. >>> import urllib >>> f =urllib.urlopen('file:///foo.txt') >>> f =urllib.urlopen('file://localhost/foo.txt') >>> f = urllib.urlopen('file://www.google.com/') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "c:\python25\lib\urllib.py", line 82, in urlopen return opener.open(url) File "c:\python25\lib\urllib.py", line 190, in open return getattr(self, name)(url) File "c:\python25\lib\urllib.py", line 457, in open_file return self.open_ftp(url) File "c:\python25\lib\urllib.py", line 538, in open_ftp ftpwrapper(user, passwd, host, port, dirs) File "c:\python25\lib\urllib.py", line 844, in __init__ self.init() File "c:\python25\lib\urllib.py", line 850, in init self.ftp.connect(self.host, self.port) File "c:\python25\lib\ftplib.py", line 129, in connect raise socket.error, msg IOError: [Errno ftp error] (10060, 'Operation timed out') >>> f =urllib.urlopen('file://127.0.0.1/foo.txt') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "c:\python25\lib\urllib.py", line 82, in urlopen return opener.open(url) File "c:\python25\lib\urllib.py", line 190, in open return getattr(self, name)(url) File "c:\python25\lib\urllib.py", line 457, in open_file return self.open_ftp(url) File "c:\python25\lib\urllib.py", line 538, in open_ftp ftpwrapper(user, passwd, host, port, dirs) File "c:\python25\lib\urllib.py", line 844, in __init__ self.init() File "c:\python25\lib\urllib.py", line 850, in init self.ftp.connect(self.host, self.port) File "c:\python25\lib\ftplib.py", line 129, in connect raise socket.error, msg IOError: [Errno ftp error] (10061, 'Connection refused') -- Tim Lesher <tles...@gmail.com>
_______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com