I have a python flask application I've been running on linux without issue, but recently it's become a requirement to run it on windows and I've run into a problem. When trying to connect to a server like this:
from flask import Flask
from flask_socketio import SocketIO
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret_key'
socketio = SocketIO(app=app, logging='DEBUG')
@socketio.on_error_default
def error_handler(e):
print('An error occurred:', e)
app.route('/')
def index():
return 'Hello, Socket.IO Client!'
if __name__ == '__main__':
socketio.run(app, port=5000)
with a socketio client like this:
import socketio
import logging
sio = socketio.Client()
logging.basicConfig(level=logging.DEBUG)
@sio.event
def connect():
print('Connected to server')
@sio.event
def disconnect():
print('Disconnected from server')
sio.connect('http://localhost:5000')
I get the error "socketio.exceptions.ConnectionError: One or more namespaces failed to connect".
This doesn't happen when running the exact same code on ubuntu. I'm losing my mind rn so any help here would be appreciated beyond words, even if it's just verifying that the error reproduces on your machine.
Python is version 3.9.13 Package versions are as follows:
And also, though I'm fairly sure it's not causing any issues here, python-socketio==5.3.0
Additional Info:
Full client log:
DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): localhost:5000
DEBUG:urllib3.connectionpool:http://localhost:5000 "GET /socket.io/?transport=polling&EIO=4&t=1688031616.8050513 HTTP/1.1" 200 None
websocket-client package not installed, only polling transport is available
ERROR:engineio.client:websocket-client package not installed, only polling transport is available
DEBUG:urllib3.connectionpool:Resetting dropped connection: localhost
DEBUG:urllib3.connectionpool:Starting new HTTP connection (2): localhost:5000
Traceback (most recent call last):
File "C:\Users\Matt\source\repos\data-art\hg-backend\Client.py", line 15, in <module>
sio.connect('http://localhost:5000')
File "C:\Users\Matt\source\repos\data-art\hg-backend\venv\lib\site-packages\socketio\client.py", line 323, in connect
raise exceptions.ConnectionError(
socketio.exceptions.ConnectionError: One or more namespaces failed to connect
DEBUG:urllib3.connectionpool:http://localhost:5000 "POST /socket.io/?transport=polling&EIO=4&sid=XDn3Nhf3Wlaepe5fAAAA HTTP/1.1" 200 None
DEBUG:urllib3.connectionpool:http://localhost:5000 "GET /socket.io/?transport=polling&EIO=4&sid=XDn3Nhf3Wlaepe5fAAAA&t=1688031618.8611357 HTTP/1.1" 200 None
Connected to server
Full server log:
* Serving Flask app 'Server' (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [29/Jun/2023 10:40:18] "GET /socket.io/?transport=polling&EIO=4&t=1688031616.8050513 HTTP/1.1" 200 -
127.0.0.1 - - [29/Jun/2023 10:40:20] "POST /socket.io/?transport=polling&EIO=4&sid=XDn3Nhf3Wlaepe5fAAAA HTTP/1.1" 200 -
127.0.0.1 - - [29/Jun/2023 10:40:20] "GET /socket.io/?transport=polling&EIO=4&sid=XDn3Nhf3Wlaepe5fAAAA&t=1688031618.8611357 HTTP/1.1" 200 -
127.0.0.1 - - [29/Jun/2023 10:41:20] "GET /socket.io/?EIO=4&transport=polling HTTP/1.1" 200 -
Have you tried this?
sio.connect('http://localhost:5000', wait_timeout = 10)