I'm using urllib.urlretrieve
to download a file, and implementing a download progress bar using the reporthook
parameter. Since urlretrieve
doesn't directly support authentication, I came up with
import urllib
def urlretrieve_with_basic_auth(url, filename=None, reporthook=None, data=None,
username="", password=""):
class OpenerWithAuth(urllib.FancyURLopener):
def prompt_user_passwd(self, host, realm):
return username, password
return OpenerWithAuth().retrieve(url, filename, reporthook, data)
This works -- but it seems like there might be a more direct way to do this (maybe with urllib2 or httplib2 or...) --any ideas?
urlgrabber has built-in support for progress bars, authentication, and more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With