Skip to main content
The 2024 Developer Survey results are live! See the results

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

17
  • 1
    Oddly enough, this worked for me on Windows when the urllib2 method wouldn't. The urllib2 method worked on Mac, though.
    – InFreefall
    Commented May 15, 2011 at 21:49
  • 7
    Bug: file_size_dl += block_sz should be += len(buffer) since the last read is often not a full block_sz. Also on windows you need to open the output file as "wb" if it isn't a text file. Commented May 25, 2011 at 17:53
  • 1
    Me too urllib and urllib2 didn't work but urlretrieve worked well, was getting frustrated - thanks :)
    – funk-shun
    Commented Jul 12, 2011 at 6:08
  • 5
    Wrap the whole thing (except the definition of file_name) with if not os.path.isfile(file_name): to avoid overwriting podcasts! useful when running it as a cronjob with the urls found in a .html file Commented May 1, 2012 at 20:15
  • 17
    According to the documentation, urllib.request.urlretrieve is a "legacy interface" and "might become deprecated in the future. docs.python.org/3/library/urllib.request.html#legacy-interface
    – Louis Yang
    Commented Dec 24, 2020 at 22:21