SSL Errors: 'Unexpected EOF'

3.7k Views Asked by At
OS: Ubuntu 16.04
Python: 2.7
OpenSSL: 1.0.2l

I am trying to submit SOAP requests through python virtual environment and I am getting SSL errors through different packages. So far I have tried suds and zeep and both produce errors no matter the request method.

# 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))

The suds code produces this error when run:

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)>

The zeep code produces this error when run:

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')",)

I've attempted both functions with a number of different authentication methods, with the same error codes no matter what changes I make. Is this a higher-level error outside of Python? The suds requests have been working just fine on another machine running on Ubuntu 14.04.

1

There are 1 best solutions below

0
On

The root cause for the second error:

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

...might be this open bug in the requests library: "Session.verify=False ignored when REQUESTS_CA_BUNDLE environment variable is set".

We've seen similar issues start all of a sudden on a specific host. It turned out that the env variable was set there recently, which started causing requests to spawn with session.verify not False despite being initialized to False. Once we removed the REQUESTS_CA_BUNDLE environment variable the errors stopped.