Flask-SocketIO
Flask-SocketIO copied to clipboard
Python socketio client not connecting to flask socketio server with SSL. JS client does.
Hello,
My python socketio client will not connect to my flask socketio server, however my js client does.
Server code:
from flask import Flask
from flask_socketio import SocketIO
app = Flask(__name__)
socketio = SocketIO(app)
@app.route('/')
def home():
return app.send_static_file('index.html')
@socketio.on('message')
def handle_message(data):
socketio.send(data)
@socketio.on('connect')
def on_connection():
print('client connected connected')
if __name__ == '__main__':
socketio.run(app, host = 'myIP', port = '443', debug = True, keyfile = 'KEYFILELOCATION', certfile = 'CERTFILELOCATION', server_side = True)
Python Client code:
import socketio
sio = socketio.Client()
sio.connect('https://myIP:443', wait=True, wait_timeout= 5)
sio.send("test")
JS Client Code:
var sio = io.connect('https://myIP:443')
sio.send("test")
The error:
raise exceptions.ConnectionError(
engineio.exceptions.ConnectionError: HTTPConnectionPool(host='myIP', port=443): Max retries exceeded with url: /socket.io/?transport=polling&EIO=4&t=1635512584.756163 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x00000220CC652C10>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it'))
PIP freeze: python-socketio==5.4.1 python-engineio==4.3.0 Flask-SocketIO==5.1.1
Is myIP a hostname, or are you using it as a placeholder for a x.x.x.x IP address? If it is an IP address, how do you intend for SSL certificate verification to work?
Sorry yes, "myIP" is a placeholder. My python client can connect when not using SSL, it is only when I include the port 443 and cert keys that it doesn't work. I might also add that the app routes work perfectly with SSL encryption. My only problem is with the python client. Thanks very much for the quick response.
@fergqwertyui you aren't giving me enough details to understand what you are doing, and besides, this package does not do any of the SSL work, this is the Python requests package that is unable to connect to your server. So what I recommend is that you work with the requests package and try sending requests to your server until you figure out what settings you need, then you can pass a requests session object to this package to be used instead of the default one.