Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSLError: [Errno bad handshake] (-1, 'Unexpected EOF') #3337

Closed
PabloLefort opened this issue Jun 15, 2016 · 9 comments
Closed

SSLError: [Errno bad handshake] (-1, 'Unexpected EOF') #3337

PabloLefort opened this issue Jun 15, 2016 · 9 comments

Comments

@PabloLefort
Copy link

Hi, i have a service for send email through SMTP with Mandrill.

# Service
from django.core.mail import EmailMessage
e = EmailMessage('test subject', 'test message', 'test@mail.com', ['me@me.com'])
e.send()

Throws this exception trace:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/opt/apps/project/virtualenv/project/lib/python2.7/site-packages/django/core/mail/message.py", line 286, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/opt/apps/project/virtualenv/project/lib/python2.7/site-packages/djrill/mail/backends/djrill.py", line 68, in send_messages
    sent = self._send(message)
  File "/opt/apps/project/virtualenv/project/lib/python2.7/site-packages/djrill/mail/backends/djrill.py", line 107, in _send
    response = requests.post(api_url, data=json.dumps(api_params, cls=JSONDateUTCEncoder))
  File "/opt/apps/project/virtualenv/project/lib/python2.7/site-packages/requests/api.py", line 109, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/opt/apps/project/virtualenv/project/lib/python2.7/site-packages/requests/api.py", line 50, in request
    response = session.request(method=method, url=url, **kwargs)
  File "/opt/apps/project/virtualenv/project/lib/python2.7/site-packages/requests/sessions.py", line 465, in request
    resp = self.send(prep, **send_kwargs)
  File "/opt/apps/project/virtualenv/project/lib/python2.7/site-packages/requests/sessions.py", line 573, in send
    r = adapter.send(request, **kwargs)
  File "/opt/apps/project/virtualenv/project/lib/python2.7/site-packages/requests/adapters.py", line 431, in send
    raise SSLError(e, request=request)
SSLError: [Errno bad handshake] (-1, 'Unexpected EOF')

Env: Red Hat 4.8.2-13, Python: 2.7.5
Libs:

Django==1.7.4
requests==2.7.0
djrill==1.3.0
pyOpenSSL==0.14

Any suggestions?

Going with this answer did not change anything.

Thanks in advance.

@Lukasa
Copy link
Member

Lukasa commented Jun 15, 2016

Unexpected EOF in this instance almost certainly means that there is a problem with your TLS handshake, and the server just tore the connection down rather than establish the TLS connection.

Firstly, you should install pyasn1 and ndg-httpsclient in addition to your current libraries: that will resolve your possible SNI issue. Then, if that didn't help, you should let me know what version of OpenSSL is installed in your system.

@PabloLefort
Copy link
Author

PabloLefort commented Jun 15, 2016

@Lukasa Already installed those libs, alike, running with --upgrade tells Requirement already up-to-date

@Lukasa
Copy link
Member

Lukasa commented Jun 15, 2016

@PabloLefort And your OpenSSL version, please?

@PabloLefort
Copy link
Author

@Lukasa OpenSSl version: OpenSSL 1.0.1e-fips 11 Feb 2013

@Lukasa
Copy link
Member

Lukasa commented Jun 15, 2016

Right, so there's no immediately obvious set of problems there. Are you familiar with Wireshark? If so, it'd be very convenient if you could grab a packet capture of the failing connection.

@PabloLefort
Copy link
Author

I'm not familiar but i will try to grab the packet and post the response.
Thanks.

@PabloLefort
Copy link
Author

@Lukasa So, after some investigation, installed tcpdump to see whats happening with the packets.
On my local env the connection was through TLS, but in the server first try to connect with TLS and fallback to SSL. This raise EOF Exception.
Going foward, there was some firewall closing every connection. I changed it and it works like a charm!

Thanks for all.

@ghost
Copy link

ghost commented Jun 29, 2017

I would like to note, that problems may be relating on the proxy settings. Unset https_proxy and http_proxy.

@PabloLefort
Copy link
Author

Thanks! @VladislavMesh 🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants