我有一个服务器,它期望通过经过身份验证的SSL从python2.7.6客户机发出请求。它已经在生产中运行了几个月,在我的本地开发环境中也是如此。他们都用Nginx。首先,我在Mac上开发,但是为了确定这个问题,我已经用完了一个Ubuntu14.04VM。在
从周五开始,客户机将得到400(“错误请求”)。我没有明确升级或更改任何内容。版本控制同意没有任何改变。它只在与本地(而不是生产)交谈时中断,所以我认为这是Nginx的问题。但是,它仍然可以使用cURL到local。在
这是返回的400个内容:
vagrant@deploy:/deployment/deploy_scripts/dev$ ./curl_ds_host_shell.py
<html>
<head><title>400 No required SSL certificate was sent</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<center>No required SSL certificate was sent</center>
<hr><center>nginx/1.4.6 (Ubuntu)</center>
</body>
</html>
它在卷曲上效果很好:
^{pr2}$它也适用于python3.4。似乎只有urllib2/httplib有问题(我使用的是requests,它调用urllib2/httplib)。这个直接的例子失败了:
import urllib2
import httplib
cert_filepath = '/var/lib/rt_data/ssl/rt.crt.pem'
key_filepath = '/var/lib/rt_data/ssl/rt.private_key.pem'
url = 'https://deploy_api.local:8443/auth/admin/1/hosts'
class HTTPSClientAuthHandler(urllib2.HTTPSHandler):
"""Wrapper to allow for authenticated SSL connections."""
def __init__(self, key, cert):
urllib2.HTTPSHandler.__init__(self)
self.key = key
self.cert = cert
def https_open(self, req):
# Rather than pass in a reference to a connection class, we pass in
# a reference to a function which, for all intents and purposes,
# will behave as a constructor
return self.do_open(self.getConnection, req)
def getConnection(self, host, timeout=300):
return httplib.HTTPSConnection(host, key_file=self.key, cert_file=self.cert)
opener = urllib2.build_opener(HTTPSClientAuthHandler(key_filepath, cert_filepath))
response = opener.open(url)
response_data = response.read()
print(response_data)
有人知道为什么会这样吗?在
目前没有回答
相关问题 更多 >
编程相关推荐