Python mechanize不';当需要HTTPS和代理身份验证时无法工作

Python mechanize不';当需要HTTPS和代理身份验证时无法工作,python,https,proxy,mechanize,Python,Https,Proxy,Mechanize,我使用Python 2.7.2和Mechanize 0.2.5。 当我访问互联网时,我必须通过代理服务器。我编写了以下代码,但在最后一行出现了错误。。有人对此有什么解决办法吗 import mechanize br = mechanize.Browser() br.set_debug_http(True) br.set_handle_robots(False) br.set_proxies({ "http" : "192.168.20.130:8080", "https"

我使用Python 2.7.2和Mechanize 0.2.5。
当我访问互联网时,我必须通过代理服务器。我编写了以下代码,但在最后一行出现了错误。。有人对此有什么解决办法吗

import mechanize

br = mechanize.Browser()
br.set_debug_http(True)
br.set_handle_robots(False)

br.set_proxies({
    "http"  : "192.168.20.130:8080",
    "https" : "192.168.20.130:8080",})
br.add_proxy_password("username", "password")

br.open("http://www.google.co.jp/")  # OK
br.open("https://www.google.co.jp/") # Proxy Authentication Required

我不建议你使用Mechanize,它已经过时了。看看吧,会的 让你的生活更轻松。在请求中使用代理只是这样:

import requests

proxies = {
  "http": "10.10.1.10:3128",
  "https": "10.10.1.10:1080",
}

requests.get("http://example.org", proxies=proxies)

非常感谢你。我不知道请求模块。我现在正在试。如何为代理身份验证指定用户名和密码?您需要使用代理url,如:用户名:mypassword@10.10.1.10:3128谢谢。当然你的方式被基本认证所接受。当代理服务器需要摘要身份验证时,不能在代理url中嵌入用户名和密码。我尝试了requests.auth.HTTPProxyAuth,但代理返回了407。