如何使用 Secure Web Proxy,如记录的那样 this (443,HTTPS)与 urllib2? 例如,我正在尝试
opener = urllib2.build_opener(urllib2.HTTPHandler, urllib2.HTTPSHandler,urllib2.ProxyHandler({"https": 'https://some_proxy.com:443'}))
urllib2.install_opener(opener)
但是超时了。 代理在其他应用程序中工作,例如通过 PAC 文件在浏览器中工作。
附言Proxy with urllib2不是重复的问题,因为没有关于 Secure Web Proxy 的信息。
最佳答案
您可以尝试使用 urllib3图书馆
from urllib3 import ProxyManager
http = ProxyManager("https://some.proxy.com:8080/")
response = http.request('GET', 'https://stackoverflow.com/')
如果你也想发送 header 到代理,那么
from urllib3 import ProxyManager, make_headers
default_headers = make_headers(proxy_basic_auth='username:password')
http = ProxyManager("https://some.proxy.com:8080/", headers=default_headers)
response = http.request('GET', 'https://stackoverflow.com/')
关于Python 2.7 (urllib2)。如何使用 SSL HTTPS 代理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56100725/