SSL错误:'意外的EOF'

时间:2017-09-14 21:57:32

标签: python python-2.7 ubuntu wsdl suds

OS: Ubuntu 16.04
Python: 2.7
OpenSSL: 1.0.2l

我正在尝试通过python虚拟环境提交SOAP请求,并且我通过不同的包获得SSL错误。到目前为止,我已经尝试过suds和zeep,无论请求方法如何都会产生错误。

# credentials
tuser = args['user']
tpass = args['pass']
url = 'https://soapendpoint.com/services?wsdl'

# in suds
from suds.client import Client
sclient = Client(url, username=tuser, password=tpass)

# in zeep
from zeep import Client
from zeep.wsse.username import UsernameToken
zclient = Client(url, wsse=UsernameToken(tuser,tpass))

运行时,suds代码会产生此错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/data/virtenvs/venv27/lib/python2.7/site-packages/suds/client.py", line 112, in __init__
    self.wsdl = reader.open(url)
  File "/home/data/virtenvs/venv27/lib/python2.7/site-packages/suds/reader.py", line 152, in open
    d = self.fn(url, self.options)
  File "/home/data/virtenvs/venv27/lib/python2.7/site-packages/suds/wsdl.py", line 136, in __init__
    d = reader.open(url)
  File "/home/data/virtenvs/venv27/lib/python2.7/site-packages/suds/reader.py", line 79, in open
    d = self.download(url)
  File "/home/data/virtenvs/venv27/lib/python2.7/site-packages/suds/reader.py", line 95, in download
    fp = self.options.transport.open(Request(url))
  File "/home/data/virtenvs/venv27/lib/python2.7/site-packages/suds/transport/https.py", line 60, in open
    return  HttpTransport.open(self, request)
  File "/home/data/virtenvs/venv27/lib/python2.7/site-packages/suds/transport/http.py", line 62, in open
    return self.u2open(u2request)
  File "/home/data/virtenvs/venv27/lib/python2.7/site-packages/suds/transport/http.py", line 118, in u2open
    return url.open(u2request, timeout=tm)
  File "/usr/local/lib/python2.7/urllib2.py", line 429, in open
    response = self._open(req, data)
  File "/usr/local/lib/python2.7/urllib2.py", line 447, in _open
    '_open', req)
  File "/usr/local/lib/python2.7/urllib2.py", line 407, in _call_chain
    result = func(*args)
  File "/usr/local/lib/python2.7/urllib2.py", line 1241, in https_open
    context=self._context)
  File "/usr/local/lib/python2.7/urllib2.py", line 1198, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error EOF occurred in violation of protocol (_ssl.c:661)>

运行时,zeep代码会产生此错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/data/virtenvs/venv27/lib/python2.7/site-packages/zeep/client.py", line 123, in __init__
    self.wsdl = Document(wsdl, self.transport, strict=strict)
  File "/home/data/virtenvs/venv27/lib/python2.7/site-packages/zeep/wsdl/wsdl.py", line 79, in __init__
    document = self._get_xml_document(location)
  File "/home/data/virtenvs/venv27/lib/python2.7/site-packages/zeep/wsdl/wsdl.py", line 140, in _get_xml_document
    location, self.transport, self.location, strict=self.strict)
  File "/home/data/virtenvs/venv27/lib/python2.7/site-packages/zeep/loader.py", line 72, in load_external
    content = transport.load(url)
  File "/home/data/virtenvs/venv27/lib/python2.7/site-packages/zeep/transports.py", line 110, in load
    content = self._load_remote_data(url)
  File "/home/data/virtenvs/venv27/lib/python2.7/site-packages/zeep/transports.py", line 125, in _load_remote_data
    response = self.session.get(url, timeout=self.load_timeout)
  File "/home/data/virtenvs/venv27/lib/python2.7/site-packages/requests/sessions.py", line 487, in get
    return self.request('GET', url, **kwargs)
  File "/home/data/virtenvs/venv27/lib/python2.7/site-packages/requests/sessions.py", line 475, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/data/virtenvs/venv27/lib/python2.7/site-packages/requests/sessions.py", line 585, in send
    r = adapter.send(request, **kwargs)
  File "/home/data/virtenvs/venv27/lib/python2.7/site-packages/requests/adapters.py", line 477, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: ("bad handshake: SysCallError(-1, 'Unexpected EOF')",)

我尝试使用多种不同的身份验证方法尝试这两种功能,无论我做了什么更改,都会使用相同的错误代码。这是Python之外的更高级错误吗? suds请求在Ubuntu 14.04上运行的另一台机器上运行正常。

1 个答案:

答案 0 :(得分:0)

第二个错误的根本原因:

requests.exceptions.SSLError: ("bad handshake: SysCallError(-1, 'Unexpected EOF')",)

...可能是请求库中的this open bug:“ Session.verify =设置了REQUESTS_CA_BUNDLE环境变量时将忽略False”。

我们已经看到类似的问题突然在特定主机上开始。事实证明,env变量是最近在此处设置的,尽管已初始化为False,但它开始导致使用session.verify不是False生成请求。一旦我们删除了REQUESTS_CA_BUNDLE环境变量,错误就会停止。