Python 2.7 (urllib2)。如何使用 SSL HTTPS 代理?

标签 python ssl https proxy urllib2

如何使用 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/

相关文章:

python - Flask 表单仅返回 FALSE 的问题

python - 在 Python 中自动键入转换参数

linux - 如何在 linux 中使用 tomcat(clientauth ="true") 构建 ssl

java - 如何调用 AWS Lambda 函数的 ssl 端点

c# - 如何将我的 Azure 站点启用为 https 而不是 http?

node.js - SSL 安全连接是否可以在没有浏览器调用的情况下使用?

java - 如何确保客户端-服务器应用程序中的通信安全?

python - 从字典中按位置获取键值

python - 根据总和对numpy数组进行排序

php - SIP2 不支持 php 中的 TLS1.2 协议(protocol)