urlretrieve() failing on me

Peter Otten __peter__ at web.de
Sat Jun 6 04:00:04 EDT 2009


Robert Dailey wrote:

>> Well I did not post the code because it is fairly complex and its hard
>> to give you the whole picture without giving you too much code. But
>> here you go, you get what you ask for:
>>
>> def Download( self ):
>> PrintSubStatus( 'Downloading...' )
>> destination = normalize( '{0}/{1}'.format( self._info.outdir,
>> self._info.file_ext ) )
>> print( self._info.url )
>> print( destination )
>> urlretrieve( self._info.url, destination )
>>
>> Both print statements are shown as
>> 
below:http://easynews.dl.sourceforge.net/sourceforge/wxwindows/mxMSW-2.8.10...
>> D:\IT\personal\haresvn\temp\mxMSW-2.8.10.zip
>>
>> I really can't figure out why this isn't working.
> 
> Wow how stupid... I was using:
> 
> mxMSW-2.8.10.zip
> 
> There is an "m" at the front, and it needs to be "w".

Time and again posting the code does help ;)
 
> wxMSW-2.8.10.zip
> 
> This URL isn't even valid, can't believe I didn't get an exception!

Sourceforge is (un)helpfully redirecting your request and Python is 
(un)helpfully following. I looks like you can avoid this by using a 
URLopener instead of the FancyURLopener implicitly used by urlretrieve():

>>> 
URLopener().retrieve("http://easynews.dl.sourceforge.net/sourceforge/wxwindows/mxMSW-2.8.10.zip", 
filename="tmp.zip")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.0/urllib/request.py", line 1476, in retrieve
    fp = self.open(url, data)
  File "/usr/lib/python3.0/urllib/request.py", line 1444, in open
    return getattr(self, name)(url)
  File "/usr/lib/python3.0/urllib/request.py", line 1622, in open_http
    return self._open_generic_http(http.client.HTTPConnection, url, data)
  File "/usr/lib/python3.0/urllib/request.py", line 1618, in 
_open_generic_http
    response.status, response.reason, response.msg, data)
  File "/usr/lib/python3.0/urllib/request.py", line 1638, in http_error
    return self.http_error_default(url, fp, errcode, errmsg, headers)
  File "/usr/lib/python3.0/urllib/request.py", line 1644, in 
http_error_default
    raise HTTPError(url, errcode, errmsg, headers, None)
urllib.error.HTTPError: HTTP Error 302: Found

Peter




More information about the Python-list mailing list