Background: I use urllib.urlretrieve , unlike any other function in urllib* modules, because of the support for the hook function (see reporthook below) .. which is used to display a text progress bar. This is Python> = 2.6.
>>> urllib.urlretrieve(url[, filename[, reporthook[, data]]])
However, urlretrieve so dumb that it leaves no way to detect the status of an HTTP request (for example: was it 404 or 200?).
>>> fn, h = urllib.urlretrieve('http://google.com/foo/bar') >>> h.items() [('date', 'Thu, 20 Aug 2009 20:07:40 GMT'), ('expires', '-1'), ('content-type', 'text/html; charset=ISO-8859-1'), ('server', 'gws'), ('cache-control', 'private, max-age=0')] >>> h.status '' >>>
What is the best way to download a remote hook-enabled HTTP file (to show a progress bar) and decent HTTP error handling?
Sridhar Ratnakumar Aug 20 '09 at 20:14 2009-08-20 20:14
source share