Python Nginx返回400,用于具有经过身份验证的SSL的请求
我有一个服务器,它期望通过经过身份验证的SSL从Python 2.7.6客户端发出请求。它已经在生产环境中工作了几个月,在我当地的开发环境中也是如此。它们都使用Nginx。基本上,我是在Mac上开发的,但是为了确定这个问题,我用光了Ubuntu 14.04虚拟机 从周五开始,客户机将收到400(“错误请求”)。我没有明确升级或更改任何内容。版本控制同意没有任何更改。它只在与本地(而不是生产)对话时才会中断,因此我认为这是Nginx的问题。但是,它仍然使用cURL to local 这是返回的400个内容:Python Nginx返回400,用于具有经过身份验证的SSL的请求,python,nginx,urllib2,Python,Nginx,Urllib2,我有一个服务器,它期望通过经过身份验证的SSL从Python 2.7.6客户端发出请求。它已经在生产环境中工作了几个月,在我当地的开发环境中也是如此。它们都使用Nginx。基本上,我是在Mac上开发的,但是为了确定这个问题,我用光了Ubuntu 14.04虚拟机 从周五开始,客户机将收到400(“错误请求”)。我没有明确升级或更改任何内容。版本控制同意没有任何更改。它只在与本地(而不是生产)对话时才会中断,因此我认为这是Nginx的问题。但是,它仍然使用cURL to local 这是返回的40
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>
它也适用于Python 3.4。这似乎只是urllib2/httplib的问题(我使用的是请求,它调用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)
有人知道为什么会这样吗
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)