urllib2 FTP Weirdness

Hans Mulder hansmu at xs4all.nl
Thu Jan 24 01:45:31 CET 2013


On 24/01/13 00:58:04, Chris Angelico wrote:
> On Thu, Jan 24, 2013 at 7:07 AM, Nick Cash
> <nick.cash at npcinternational.com> wrote:
>> Python 2.7.3 on linux
>>
>> This has me fairly stumped. It looks like
>>         urllib2.urlopen("ftp://some.ftp.site/path").read()
>> will either immediately return '' or hang indefinitely. But
>>         response = urllib2.urlopen("ftp://some.ftp.site/path")
>>         response.read()
>> works fine and returns what is expected. This is only an issue with urllib2, vanilla urllib doesn't do it.
>>
>> The site I first noticed it on is private, but I can reproduce it with "ftp://ftp2.census.gov/".
> 
> Confirmed on 2.6.5 on Windows, fwiw. This is extremely weird.

It works fine with 2.7.3 on my Mac.

> Possibly it's some kind of race condition??

If urllib2 is using active mode FTP, then a firewall on your box
could explain what you're seeing.  But then, that's why active
mode is hardly used these days.


Hope this helps,

-- HansM



More information about the Python-list mailing list