通过代理进行PKI身份验证,Python 2.6.6

时间:2019-02-20 22:03:18

标签: ssl urllib2 python-2.6 http-proxy pki

我正在尝试通过代理进行基于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")

上面的实现效果很好,直到我将代理添加到request.get()

response = requests.get(url, headers=headers, proxies=proxies, cert=(cert,key), timeout=300)

返回以下错误:

  

HTTP / 1.0 401未经授权
  WWW-Authenticate:基本领域=“”
  服务器:SomeServer
  连接:保持活动   内容长度:35

1 个答案:

答案 0 :(得分:0)

问题出在我的代理设置上,它还在解密HTTPS流量,因为它没有通过原始证书。在我禁用HTTPS解密后,它可以正常工作。