urlretrieve() failing on me

P

Peter Otten

Robert said:
Can you show me your test code please?

Here's mine:

$ cat retriever.py
import urllib.request
import os

def report(*args):
print(args)

url = "http://softlayer.dl.sourceforge.net/sourceforge/wxwindows/wxMSW-2.8.10.zip"
filename = url.rsplit("/")[-1]

urllib.request.urlretrieve(url, filename=filename, reporthook=report)
print(os.path.getsize(filename))
$

If you had shown your code in the first place the problem might have been solved by now...

Peter
 
R

Robert Dailey

Can you show me your test code please?

Here's mine:

$ cat retriever.py
import urllib.request
import os

def report(*args):
    print(args)

url = "http://softlayer.dl.sourceforge.net/sourceforge/wxwindows/wxMSW-2.8.1..."
filename = url.rsplit("/")[-1]

urllib.request.urlretrieve(url, filename=filename, reporthook=report)
print(os.path.getsize(filename))
$

If you had shown your code in the first place the problem might have been solved by now...

Peter

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.zip
D:\IT\personal\haresvn\temp\mxMSW-2.8.10.zip

I really can't figure out why this isn't working.
 
R

Robert Dailey

Here's mine:
$ cat retriever.py
import urllib.request
import os
def report(*args):
    print(args)
urllib.request.urlretrieve(url, filename=filename, reporthook=report)
print(os.path.getsize(filename))
$
If you had shown your code in the first place the problem might have been solved by now...

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".

wxMSW-2.8.10.zip

This URL isn't even valid, can't believe I didn't get an exception!
 
G

greg

Robert said:
This URL isn't even valid, can't believe I didn't get an exception!

My guess is that if you look at the data it
downloaded, you'll find it's a 404 response
page or something similar.
 
P

Peter Otten

Robert said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top