socketio-client won't connect to wss flask-socketio server
See original GitHub issueI get the following error when trying to connect to a SSL encrypted Flask-socketio server using the websocket transport.
Attempting WebSocket connection to wss://localhost/socket.io/?transport=websocket&EIO=3
Traceback (most recent call last):
File "client.py", line 6, in <module>
sio.connect('https://localhost', transports=['websocket'])
File "/Library/Python/3.7/site-packages/socketio/client.py", line 279, in connect
six.raise_from(exceptions.ConnectionError(exc.args[0]), None)
File "<string>", line 3, in raise_from
socketio.exceptions.ConnectionError: Connection error
Is there something more I need to configure for WSS to work? Unencrypted web sockets seem to work just fine.
Server.py
from flask import Flask
from flask_socketio import SocketIO
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app, logger=True)
socketio.run(app, host='0.0.0.0', port=443, debug=True, keyfile='snakeoil.key', certfile='snakeoil.pem')
Client.py
import socketio
sio = socketio.Client(ssl_verify=False, logger=True, engineio_logger=True)
sio.connect('https://localhost', transports=['websocket'])
sio.disconnect()
Flask==1.1.1 Flask-SocketIO==4.3.0 python-engineio==3.12.1 python-socketio==4.5.1
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Troubleshooting connection issues | Socket.IO
You are trying to reach a plain WebSocket server; The server is not reachable; The client is not compatible with the version of...
Read more >Flask-socketio issues with https, http, wss unable to connect in ...
In io.connect on the client side, the connect parameter used https:// + document.domain + location.port but the server was using http:// so ...
Read more >Flask-SocketIO — Flask-SocketIO documentation
Flask -SocketIO gives Flask applications access to low latency bi-directional communications between the clients and the server. The client-side application ...
Read more >Create a Secure Chat Application with Socket.IO and React
You should not receive any error messages but you also will not see much at this point because the server is not connecting...
Read more >Implementing WebSocket communication in Next.js
Creating the server side ;, which does not exist by default and shows that the socket connection is not in place. If this...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
enabling engineio_logger shed enough light on the issue.
Adding
cors_allowed_origins=[]
to the server resolves the issue. This fix is a little dubious but acceptableUse
cors_allowed_origins='http://localhost:8080'
for increased security.