urllib2 FTP Weirdness
Nick Cash
nick.cash at npcinternational.com
Wed Jan 23 15:07:56 EST 2013
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/".
I've tested the equivalent code on Python 3.2.3 and get the same results, except that one time I got a socket error (may have been a spurious network blip, though).
I'm at a loss as to how that could even work differently. My only guess is that by not having a reference to the addinfourl response object, something important is getting garbage collected or closed... that seems like a stretch, though. Is this a urllib2 bug, or am I crazy?
-Nick Cash
More information about the Python-list
mailing list