8
我使用urllib.urlretrieve
來下載文件並使用reporthook
參數實現下載進度欄。由於urlretrieve
不直接支持認證,我想出了Python - 使用進度條和基本身份驗證通過HTTP下載文件
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)
此工程 - 但它看起來有可能做到這一點(也許用的urllib2或httplib2的或......)更直接的方式 - -有任何想法嗎?
不錯,將完美適用於我當前的項目 – rinti 2010-01-01 04:58:41