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

ssl configurations can not get passed to gevent #188

Closed
muatik opened this issue Jan 1, 2016 · 1 comment · Fixed by #189
Closed

ssl configurations can not get passed to gevent #188

muatik opened this issue Jan 1, 2016 · 1 comment · Fixed by #189
Labels

Comments

@muatik
Copy link
Contributor

muatik commented Jan 1, 2016

Before upgrading to flask-socketio's 1.x version, I was able to use socketio with ssl. After upgrading, and changing nothing on my side, I am getting the following error output.

<socket fileno=19 sock=10.125.16.202:5000 peer=149.101.37.2:27486>: Expected GET method: '\x16\x03\x01\x00\x82\x01\x00\x00~\x03\x01V\x85z\x15#\xbc\x9b\x13\xd7:f\xb0a\xd0\xf7\xde\xcd\x1b\xf6\x15fb\x99RaUg\xd9\x89\x1d\xe2\x0b\x00\x00\x18\xc0\x14\xc0\x13\xc0\n'
Traceback (most recent call last):
  File "/usr/lib/python2.7/logging/__init__.py", line 874, in emit
    stream.write(fs % msg.encode("UTF-8"))
  File "/usr/lib/python2.7/encodings/utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0x82 in position 87: invalid start byte
Logged from file handler.py, line 237

My code is similar to this:

app = Flask(__name__)
app.debug = True
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)

# .... some other code

SOCKET_SSL_KEY_FILE = '/etc/something.key'
SOCKET_SSL_CERT_FILE = '/etc/something.crt'

if __name__ == '__main__':
    socketio.run(
        app,
        host="0.0.0.0",
        port=5000,
        keyfile=SOCKET_SSL_KEY_FILE,
        certfile=SOCKET_SSL_CERT_FILE)

I investigated a little bit and came across that ssl keyword arguments were not passed to gevent side. https://github.com/miguelgrinberg/Flask-SocketIO/blob/master/flask_socketio/__init__.py#L398

 self.wsgi_server = pywsgi.WSGIServer(
                    (host, port), app, handler_class=WebSocketHandler,
                    log=log)

when I change the statement like the following it works:

self.wsgi_server = pywsgi.WSGIServer(
                    (host, port), app, handler_class=WebSocketHandler,
                    log=log, **kwargs)

If you confirm the problem and the offered solution, I can send a quick pull request.

@miguelgrinberg
Copy link
Owner

Yep, I agree on the problem and the solution. I actually do this for eventlet, but somehow missed it for gevent. Feel free to send the PR, I'll merge right away. Thanks!

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

Successfully merging a pull request may close this issue.

2 participants