3

How should I translate app.run() to sockio.run() with SSL?

I have below app start code to run with flask development server

if __name__=='__main__':
    app.run(ssl_context=(ssl_cert, ssl_key))

I am now trying to start it with socketio like below

if __name__=='__main__':
    socketio.run(app, host='0.0.0.0', port=80, debug=True)

However, I cannot figure out how to pass cert into this call.
What do I have to do to make this work?

Kay
  • 1,235
  • 2
  • 13
  • 27

2 Answers2

5

Old question but I'll give an answer anyway. Try something like this:

if __name__=='__main__':
    socketio.run(app, host='0.0.0.0', port=80, debug=True, keyfile='key.pem', certfile='cert.pem')
IrogSinta
  • 51
  • 1
  • 4
5

I was having the same issue. This is equivalent to what worked for me.

if __name__ == '__main__':
    socketio.run(app, host="0.0.0.0", port="80", debug=True, ssl_context=('cert.pem', 'key.pem'))

For some reason I had to manually enter the server address in a web browser ( i.e. https://127.0.0.1:5000/ ) before my angular app was able to access the flask socketio https server, but I think that is a client side issue I need to work out.

avtrev
  • 66
  • 1
  • 2