无法使用任何python请求验证来自客户端的ssl-certificate,httplib / httplib2,urllib / urlib2

时间:2017-11-24 07:43:30

标签: python python-requests urllib2 urllib httplib

这个问题是重复的。但我仍在问,因为我没有从给定的答案中找到任何解决方案。所以大家不要让它重复,而是帮我解决这个问题。

我使用bottle(paste)运行我的服务器作为https。当试图从java和postman访问时,它正在验证并且响应即将到来。

使用的版本: python 2.7.13

  
    
      

请求。的版本       '2.11.1'       导入密码学       加密。的版本       '2.1.3'       导入OpenSSL       OpenSSL的。的版本       '17 .3.0'

    
  

但不幸的是,当尝试从python模块访问时 - 它正在抛出问题。 ?

requests.post(url, verify=_certfile, proxies=proxies) #tried #failed to verify certificate

urllib2.urlopen(url, data=data, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
        cafile=None, capath=None, cadefault=False, context=context)  #tried #failed to verify certificate

import httplib2

http = httplib2.Http(disable_ssl_certificate_validation=True)
headers, content = http.request(url, "POST", body=data, headers=headers)#tried #failed to verify certificate

httplib.HTTPSConnection(host='10.201.41.50', port=8018, key_file=key_file, cert_file=cert_file, strict=None, context=context) #tried #failed to verify certificate

我的服务器正在使用使用瓶子框架的粘贴服务器运行。

ssl_cxt = SSL.Context(SSL.SSLv23_METHOD)
...
...
ssl_cxt.set_verify(SSL.VERIFY_PEER | SSL.VERIFY_FAIL_IF_NO_PEER_CERT, verify_cb)
paste.httpserver.serve(app, host=IP, port=PORT, server_version=" ", ssl_context=ssl_cxt)

我面临的问题(与每个lib不同)

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "Continuum\Anaconda2\lib\site-packages\requests\api.py", line 70, in get
return request('get', url, params=params, **kwargs)
File "Continuum\Anaconda2\lib\site-packages\requests\api.py", line 56, in request
return session.request(method=method, url=url, **kwargs)
File "Continuum\Anaconda2\lib\site-packages\requests\sessions.py", line 475, in request
resp = self.send(prep, **send_kwargs)
File "Continuum\Anaconda2\lib\site-packages\requests\sessions.py", line 596, in send
r = adapter.send(request, **kwargs)
File "Continuum\Anaconda2\lib\site-packages\requests\adapters.py", line 497, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: unknown error (_ssl.c:2947)

============

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "Continuum\Anaconda2\lib\site-packages\requests\api.py", line 70, in get
return request('get', url, params=params, **kwargs)
File "Continuum\Anaconda2\lib\site-packages\requests\api.py", line 56, in request
return session.request(method=method, url=url, **kwargs)
File "Continuum\Anaconda2\lib\site-packages\requests\sessions.py", line 475, in request
resp = self.send(prep, **send_kwargs)
File "Continuum\Anaconda2\lib\site-packages\requests\sessions.py", line 596, in send
r = adapter.send(request, **kwargs)
File "Continuum\Anaconda2\lib\site-packages\requests\adapters.py", line 497, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate 
verify failed (_ssl.c:661)

  File "Continuum\Anaconda2\lib\httplib.py", line 1038, in endheaders
  self._send_output(message_body)
  File "Continuum\Anaconda2\lib\httplib.py", line 882, in _send_output
  self.send(msg)
  File "Continuum\Anaconda2\lib\httplib.py", line 844, in send
  self.connect()
  File "Continuum\Anaconda2\lib\httplib.py", line 1262, in connect
  self.sock = self._context.wrap_socket(self.sock,
  AttributeError: 'Context' object has no attribute 'wrap_socket'

0 个答案:

没有答案