ssl - 通过代理进行 PKI 身份验证,python 2.6.6
问题描述
我正在尝试通过代理进行基于 PKI 的身份验证。它在没有代理的情况下运行良好,但作为我添加代理信息它返回 401 错误。
proxies = {
'http': "http://10.192.72.155:8080",
'https': "http://10.192.72.155:8080",
}
def open_url(url, key, cert):
headers = {"User-Agent": "<custom>", "Accept": "<custom>"}
response = requests.get(url, headers=headers, cert=(cert,key), timeout=300)
print response.headers, response
open_url("https://api.example.com/product/LatestUpdate", "/usr/bin/dev_certs/test_cert.key", "/usr/bin/dev_certs/test_cert.pem")
上面的实现效果很好,直到我将代理添加到 requests.get()
response = requests.get(url, headers=headers, proxies=proxies, cert=(cert,key), timeout=300)
返回以下错误:
HTTP/1.0 401 未经授权
的 WWW-Authenticate: Basic realm=""
Server: SomeServer
Connection: Keep-Alive Content-Length: 35
解决方案
问题是我的代理设置,它还在解密 HTTPS 流量,因此它没有通过原始证书。在我禁用 HTTPS 解密后它起作用了。
推荐阅读
- python - 如何检查字符串列是否包含子字符串,如果为真则返回行数据?
- python - 如何从 .txt 文件中读取某些字符并将它们写入 Python 中的 .csv 文件?
- python - 获取打开的每个文件的第一个、第二个和第三个日期 - Pandas
- php - 如何在没有 Bowser 的情况下禁用访问 url?
- java - Oracle Universal Installer 会弄乱我现有的数据库设置吗?
- logging - pytest-html:在使用日志记录时摆脱捕获日志中的 ASCII,因此它不显示详细信息链接?
- javascript - React 组件 JS 中的去抖动
- html - 首次加载或刷新后视频未播放
- python - Python:如何在打印函数中打印元组的单个元素
- java - 打印一条消息,说明元素不存在于 catch 块中,硒