[ python-Bugs-635453 ] urllib.urlretrieve() with ftp error

SourceForge.net noreply at sourceforge.net
Sat Jul 10 22:27:16 CEST 2004


Bugs item #635453, was opened at 2002-11-08 11:39
Message generated for change (Comment added) made by jpe
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=635453&group_id=5470

Category: Python Library
Group: Python 2.2.2
Status: Open
Resolution: None
Priority: 5
Submitted By: Bram Moolenaar (vimboss)
Assigned to: Brett Cannon (bcannon)
Summary: urllib.urlretrieve() with ftp error 

Initial Comment:
When using urllib.urlretrieve() to obtain a file
through ftp and the file is not readable the directory
listing of the file is returned.  The expected behavior
is that a "permission denied" error is generated.
The current behavior makes it impossible to detect
downloading a file failed.

To reproduce:

from urllib import urlretrieve
fname = "/pub/vim/unstable/testfile"
url = "ftp://ftp.vim.org"
resfile, h = urlretrieve(url + fname)
print "file contents: '%s'" % open(resfile).read()
print "header stuff: ", h

The result:
file contents: '-rw-------   1 506      450           
25 Nov  8 11:50 testfile
'

Using ftplib.FTP() does result in the expected error:

from ftplib import FTP
def list(s):
	print s
f = FTP("ftp.vim.org")
f.login()
f.retrbinary("RETR " + fname, list)
f.quit()

The last line of the resulting exception:
ftplib.error_perm: 550 /pub/vim/unstable/testfile:
Permission denied.


----------------------------------------------------------------------

Comment By: John Ehresman (jpe)
Date: 2004-07-10 20:27

Message:
Logged In: YES 
user_id=22785

This is evidently the intended behavior when a url for an
unreadable file is opened, but I think it would make more
sense to raise an exception.  To change the behavior so it
raises an exception, simply remove the test for an exception
reason starting with 550 from ftpwrapper.retrfile() in
urllib.py.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=635453&group_id=5470


More information about the Python-bugs-list mailing list