首页 > 解决方案 > 通过代理进行 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

标签: sslurllib2python-2.6http-proxypki

解决方案


问题是我的代理设置,它还在解密 HTTPS 流量,因此它没有通过原始证书。在我禁用 HTTPS 解密后它起作用了。


推荐阅读