Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > urllib2 FTP Weirdness

Reply
Thread Tools

urllib2 FTP Weirdness

 
 
Nick Cash
Guest
Posts: n/a
 
      01-23-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, somethingimportant is getting garbage collected or closed... that seems like a stretch, though. Is this a urllib2 bug, or am I crazy?

-Nick Cash


 
Reply With Quote
 
 
 
 
Steven D'Aprano
Guest
Posts: n/a
 
      01-24-2013
Nick Cash 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/".


Then why not give that in your example, to make running your code
easier?

I cannot reproduce the problem:


py> import urllib2
py> x = urllib2.urlopen("ftp://ftp2.census.gov/").read()
py> len(x)
5550


Works fine for me using Python 2.7.2 on Linux. I cannot see how the two
snippets you give could possibly be different. If you are using a proxy,
what happens if you bypass it?

If you can reproduce this at will, with and without proxy, with multiple
sites, then I suppose it is conceivable that it could be some sort of bug.
But I wouldn't bet on it.



--
Steven

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: urllib2 FTP Weirdness Chris Angelico Python 5 02-07-2013 09:49 PM
urllib2 weirdness when https_proxy environment variable is exported Devraj Python 2 10-29-2007 09:58 AM
Problem with: urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) Josef Cihal Python 0 09-05-2005 11:26 AM
Tkinter WEIRDNESS or Python WEIRDNESS? steve Python 4 03-13-2005 12:34 AM
Net::FTP problems getting files from Windows FTP server, but not Linux FTP Server. D. Buck Perl Misc 2 06-29-2004 02:05 PM



Advertisments