Need script to download file at known address

Radioactive Man rm at rm.rm
Fri Sep 17 03:46:42 CEST 2004

On Wed, 15 Sep 2004 17:20:43 +0200, aleaxit at (Alex Martelli)

>Radioactive Man <rm at rm.rm> wrote:
>> I am fairly new to the latest verion of Python and using it on windows
>> 95, 2000, and/or XP.  What libraries, modules, functions, etc. would I
>> need to set up a Python script to download a file, say
>> "htttp://" to my own hard drive at
>> "c:\sound\bob.wav"?  
>Something like:
>import urllib
>urllib.urlretrieve( "htttp://",
>                           'c:/sound/bob.wav')
>should be fine.
>> I haven't found any good examples of such an operation in the
>> documentation at the Python website.  Any suggestions are appreciated.
> has the docs of
>urlretrieve, and it's SO simple that I don't really see what "good
>examples" one might provide.  A book that by design is full of examples
>(hopefully good) is the Python Cookbook, which in the intro to Chapter
>10 (Network Programming) gives a slightly richer example which downloads
>several files with urllib.urlretrieve.
> may have some useful pointers,
>/Q_21048439.html has exactly the same question you asked, but you have
>to "sign up" to see the solution (always the same one).

Thanks to all who replied on this one.  I have managed to download,
but somehow the file is getting mangled when I save it to my hard
drive.  Here is the test script I came up with:

import urllib
f =  urllib.urlopen("")
g =
file = open("trash.gif", "w")

The file "trash.gif" is actually saved under "C:\Python23" in the
correct format (recognizable to *.gif viewing programs), but is so
severely mangled that I can't even recognize it visually.  It happens
every time, so I do not believe it is a random event.  My question
here is what am I doing wrong and at what stage is the file getting
mangled?  I know this method works fine with text files, but for some
reason is damaging to binary files.

The same result happened when I substituted urllib.urlretrieve() for

More information about the Python-list mailing list