<div class="gmail_quote">On Fri, Jul 9, 2010 at 12:41, Bill Janssen <span dir="ltr"><<a href="mailto:janssen@parc.com">janssen@parc.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">So, FTP is *not* the "default protocol". On the other hand, if <host></div>
actually begins with "ftp.", it's a pretty good guess that FTP will<br>
work. </blockquote><div><br></div><div>Actually, FTP *is* the default protocol for most URLs with hostnames in urllib.py.</div><div><br></div><div>urllib.open_file() delegates to open_ftp() if there's a any host other than the exact string "localhost", and open_local_file() otherwise.</div>
<div><br></div><div>>>> import urllib</div><div><div><div>>>> f =urllib.urlopen('file:///foo.txt')</div></div><div><div><div>>>> f =urllib.urlopen('file://localhost/foo.txt')</div>
</div><div><div>>>> f = urllib.urlopen('file://<a href="http://www.google.com/">www.google.com/</a>')</div></div></div></div><div>Traceback (most recent call last):</div><div> File "<stdin>", line 1, in <module></div>
<div> File "c:\python25\lib\urllib.py", line 82, in urlopen</div><div> return opener.open(url)</div><div> File "c:\python25\lib\urllib.py", line 190, in open</div><div> return getattr(self, name)(url)</div>
<div> File "c:\python25\lib\urllib.py", line 457, in open_file</div><div> return self.open_ftp(url)</div><div> File "c:\python25\lib\urllib.py", line 538, in open_ftp</div><div> ftpwrapper(user, passwd, host, port, dirs)</div>
<div> File "c:\python25\lib\urllib.py", line 844, in __init__</div><div> self.init()</div><div> File "c:\python25\lib\urllib.py", line 850, in init</div><div> self.ftp.connect(self.host, self.port)</div>
<div> File "c:\python25\lib\ftplib.py", line 129, in connect</div><div> raise socket.error, msg</div><div>IOError: [Errno ftp error] (10060, 'Operation timed out')</div></div><div>>>> f =urllib.urlopen('file://<a href="http://127.0.0.1/foo.txt">127.0.0.1/foo.txt</a>')</div>
<div>Traceback (most recent call last):</div><div> File "<stdin>", line 1, in <module></div><div> File "c:\python25\lib\urllib.py", line 82, in urlopen</div><div> return opener.open(url)</div>
<div> File "c:\python25\lib\urllib.py", line 190, in open</div><div> return getattr(self, name)(url)</div><div> File "c:\python25\lib\urllib.py", line 457, in open_file</div><div> return self.open_ftp(url)</div>
<div> File "c:\python25\lib\urllib.py", line 538, in open_ftp</div><div> ftpwrapper(user, passwd, host, port, dirs)</div><div> File "c:\python25\lib\urllib.py", line 844, in __init__</div><div> self.init()</div>
<div> File "c:\python25\lib\urllib.py", line 850, in init</div><div> self.ftp.connect(self.host, self.port)</div><div> File "c:\python25\lib\ftplib.py", line 129, in connect</div><div> raise socket.error, msg</div>
<div>IOError: [Errno ftp error] (10061, 'Connection refused')</div>-- <br>Tim Lesher <<a href="mailto:tlesher@gmail.com">tlesher@gmail.com</a>><br>