zeep requests.exceptions.SSLError :(“握手不好:错误([('SSL例程','ssl3_get_server_certificate','证书验证失败')],)”,)

时间:2017-03-23 13:26:48

标签: python ssl openssl python-requests zeep

我尝试在zethon lib for python

的帮助下创建SOAP客户端
import os
from zeep import Client
from zeep.wsse.signature import Signature

key_filename = "/etc/ssl/certs/cert.key.pem"
cert_filename = "/etc/ssl/certs/cert.crt.pem"

client = Client('https://37.230.149.6:10004/emias-soap-service/PGUServicesInfo2?wsdl', wsse=Signature(key_filename, cert_filename))

有这个例外:

Traceback (most recent call last):
  File "/home/max/bot_project/Bots_Django/TelegramBot/bot/simple_soap_client.py", line 19, in <module>
    wsse=Signature(key_filename, cert_filename))
  File "/home/max/bot_project/Bots_Django/venv/local/lib/python2.7/site-packages/zeep/client.py", line 120, in __init__
    self.wsdl = Document(wsdl, self.transport, strict=strict)
  File "/home/max/bot_project/Bots_Django/venv/local/lib/python2.7/site-packages/zeep/wsdl/wsdl.py", line 76, in __init__
    document = self._get_xml_document(location)
  File "/home/max/bot_project/Bots_Django/venv/local/lib/python2.7/site-packages/zeep/wsdl/wsdl.py", line 137, in _get_xml_document
    location, self.transport, self.location, strict=self.strict)
  File "/home/max/bot_project/Bots_Django/venv/local/lib/python2.7/site-packages/zeep/loader.py", line 66, in load_external
    content = transport.load(url)
  File "/home/max/bot_project/Bots_Django/venv/local/lib/python2.7/site-packages/zeep/transports.py", line 111, in load
    content = self._load_remote_data(url)
  File "/home/max/bot_project/Bots_Django/venv/local/lib/python2.7/site-packages/zeep/transports.py", line 126, in _load_remote_data
    response = self.session.get(url, timeout=self.load_timeout)
  File "/home/max/bot_project/Bots_Django/venv/local/lib/python2.7/site-packages/requests/sessions.py", line 501, in get
    return self.request('GET', url, **kwargs)
  File "/home/max/bot_project/Bots_Django/venv/local/lib/python2.7/site-packages/requests/sessions.py", line 488, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/max/bot_project/Bots_Django/venv/local/lib/python2.7/site-packages/requests/sessions.py", line 609, in send
    r = adapter.send(request, **kwargs)
  File "/home/max/bot_project/Bots_Django/venv/local/lib/python2.7/site-packages/requests/adapters.py", line 497, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: ("bad handshake: Error([('SSL routines', 'ssl3_get_server_certificate', 'certificate verify failed')],)",)

如何修复此异常以及我的代码有什么问题?

3 个答案:

答案 0 :(得分:1)

这对我有用 -

Camunda

答案 1 :(得分:0)

我认为你需要使用verify = False

答案 2 :(得分:0)

Session对象(通过Client对象明确传递给您的zeep Transport对象,并设置verify=False

这是一个例子:

from requests import Session
from zeep import Client
from zeep.transports import Transport
from zeep.wsse.signature import Signature

import os

key_filename = "/etc/ssl/certs/cert.key.pem"
cert_filename = "/etc/ssl/certs/cert.crt.pem"

session = Session()
session.verify = False

client = Client(
    'https://37.230.149.6:10004/emias-soap-service/PGUServicesInfo2?wsdl',
    wsse=Signature(key_filename, cert_filename),
    transport=Transport(session=session)
)

或者,您也应该这样做,是将session.verify设置为CA Authority证书(服务器ROOT和SUB证书上安装的证书的颁发者),例如:

session.verify = "/path/to/ca_cert.pem"

如果证书的颁发者与ca_cert.pem中的颁发者相同,这基本上会告诉您的python脚本信任URL。