urllib2 FTP Weirdness

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu Feb 7 03:43:24 CET 2013

On Thu, 07 Feb 2013 10:06:32 +1100, Cameron Simpson wrote:

> | 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()
> Timing. (Let me say I consider this scenario unlikely, very unlikely.
> But...)
> If the latter is consistently slightly slower 

On my laptop, the difference is of the order of 10 microseconds. About 
half a million times smaller than the amount of time it takes to open the 
connection in the first place.

> then the firewall may be
> an issue if active FTP is being used. "Active" FTP requires the FTP
> server to connect to you to deliver the data: your end opens a listening
> TCP socket and says "get", supplying the socket details.

If you are thinking that the socket gets closed if the read is delayed 
too much, that doesn't explain the results you are getting. The read 
succeeds when there is a delay, not when there is no delay. Almost as if 
something is saying "oh, the read request came in too soon after the 
connection was made, must block".

What can I say? I cannot reproduce the issue you are having. If you can 
reproduce it, try again without the firewall. If bypassing the firewall 
makes the issue go away, then go and yell at your network admins until 
they fix it.


More information about the Python-list mailing list