代码之家  ›  专栏  ›  技术社区  ›  dF.

Python-使用进度条和基本身份验证通过HTTP下载文件

  •  8
  • dF.  · 技术社区  · 17 年前

    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)
    

    1 回复  |  直到 17 年前
        1
  •  7
  •   Mike Pelley    7 年前
    推荐文章