I'm trying to run a simple SSL-enabled application using gevent.pywsgi
's WSGIServer
. However, I keep getting SSLError: [Errno 8] _ssl.c:510: EOF occurred in violation of protocol
after about 10-15 second after first request is made (from Chrome), during what I assume is an attempt to re-handshake:
Traceback (most recent call last):
File "D:\SOMEPATH\lib\site-packages\gevent\greenlet.py", line 327, in run
result = self._run(*self.args, **self.kwargs)
File "D:\SOMEPATH\lib\site-packages\gevent\server.py", line 102, in wrap_socket_and_handle
ssl_socket = self.wrap_socket(client_socket, **self.ssl_args)
File "D:\SOMEPATH\lib\site-packages\gevent\ssl.py", line 383, in wrap_socket
ciphers=ciphers)
File "D:\SOMEPATHK\lib\site-packages\gevent\ssl.py", line 94, in __init__
self.do_handshake()
File "D:\SOMEPATH\lib\site-packages\gevent\ssl.py", line 305, in do_handshake
return self._sslobj.do_handshake()
SSLError: [Errno 8] _ssl.c:510: EOF occurred in violation of protocol
<Greenlet at 0x4998850: <bound method WSGIServer.wrap_socket_and_handle of <WSGIServer at 0x499d6d0 fileno=500 address=127.0.0.1:12344>>(<socket at 0x49f50d0 fileno=912 sock=127.0.0.1:123, ('127.0.0.1', 6398))> failed with SSLError
The page loads just fine. My minimal working example is as follows:
from gevent import monkey
monkey.patch_all()
from gevent import ssl
from flask import Flask
from gevent.pywsgi import WSGIServer
app = Flask(__name__)
@app.route('/')
def main():
return 'hi!'
server = WSGIServer(
('127.0.0.1', 12344),
app,
keyfile='server.key',
certfile='server.crt',
ssl_version=ssl.PROTOCOL_TLSv1,
)
print 'Serving..'
server.serve_forever()
- I have tried forcing the TLSv1 version of the protocol, as suggested in numerous other threads, most of which reference this answer. This can be seen in the MWE.
- I have verified that I get no error using Flask's default, non-
gevent
in-built server, with SSL setup in a way similar to this snippet. - Studying the sources. Eventually, the exception comes from a wrapped C function after several
SSL_ERROR_WANT_READ
"exceptions" are handled indo_handshake()
.
I use gevent==1.0.1
and Python 2.7.8 (default, Jun 30 2014, 16:03:49)
on a Windows machine right now.
How do I get rid of that error?