urllib2 FTP Weirdness

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu Jan 24 05:12:16 CET 2013


On Thu, 24 Jan 2013 01:45:31 +0100, Hans Mulder wrote:

> 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.


Explain please?

I cannot see how the firewall could possible distinguish between using a 
temporary variable or not in these two snippets:

# no temporary variable hangs, or fails
urllib2.urlopen("ftp://ftp2.census.gov/").read()


# temporary variable succeeds
response = urllib2.urlopen("ftp://ftp2.census.gov/")
response.read()



-- 
Steven



More information about the Python-list mailing list