我urllib.urlretrieve用于下载文件,并使用参数实现下载进度条reporthook。由于urlretrieve不直接支持身份验证,我想出了
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 或......)——有什么想法吗?