【问题标题】:Python - downloading a file over HTTP with progress bar and basic authenticationPython - 通过 HTTP 下载带有进度条和基本身份验证的文件
【发布时间】:2009-01-15 19:52:18
【问题描述】:

我正在使用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 或...)——有什么想法吗?

【问题讨论】:

    标签: python http download


    【解决方案1】:

    urlgrabber 内置了对进度条、身份验证等的支持。

    【讨论】:

    • Ignacio 的 URI 现在 (2010-06-25) 已过期,更新为 urlgrabber
    猜你喜欢
    • 2018-04-14
    • 1970-01-01
    • 2017-01-17
    • 1970-01-01
    • 2018-01-24
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 2015-05-13
    相关资源
    最近更新 更多