【问题标题】:Python HTTPS client with basic authentication via proxy通过代理进行基本身份验证的 Python HTTPS 客户端
【发布时间】:2009-09-21 07:35:48
【问题描述】:

从 Python 中,我想通过带有基本身份验证的 HTTPS 从网站检索内容。我需要磁盘上的内容。我在 Intranet 上,信任 HTTPS 服务器。平台是 Windows 上的 Python 2.6.2。

我一直在玩 urllib2,但是到目前为止没有成功。

我正在运行一个解决方案,通过 os.system() 调用 wget:

wget_cmd = r'\path\to\wget.exe -q -e "https_proxy = http://fqdn.to.proxy:port" --no-check-certificate --http-user="username" --http-password="password" -O path\to\output https://fqdn.to.site/content'

我想摆脱 os.system()。这在 Python 中可行吗?

【问题讨论】:

    标签: python proxy https basic-authentication


    【解决方案1】:

    代理和 https 无法与 urllib2 一起使用 for a long time。它将在python 2.6(v2.6.3)的下一个发布版本中修复。

    与此同时,您可以重新实现正确的支持,这就是我们为 mercurial 所做的:http://hg.intevation.org/mercurial/crew/rev/59acb9c7d90f

    【讨论】:

      【解决方案2】:

      试试这个(请注意,您还必须填写服务器领域):

      import urllib2
      authinfo = urllib2.HTTPBasicAuthHandler()
      authinfo.add_password(realm='Fill In Realm Here',
                            uri='https://fqdn.to.site/content',
                            user='username',
                            passwd='password')
      proxy_support = urllib2.ProxyHandler({"https" : "http://fqdn.to.proxy:port"})
      opener = urllib2.build_opener(proxy_support, authinfo)
      fp = opener.open("https://fqdn.to.site/content")
      open(r"path\to\output", "wb").write(fp.read())
      

      【讨论】:

        【解决方案3】:

        你也可以试试这个: http://code.google.com/p/python-httpclient/

        (也支持服务器证书的验证。)

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2014-03-31
          • 1970-01-01
          • 2011-05-20
          • 2014-04-01
          • 1970-01-01
          • 1970-01-01
          • 2012-01-30
          • 2017-09-18
          相关资源
          最近更新 更多