RuntimeError: The gevent-websocket server is not configured appropriately. See the Deployment section of the documentation for more information. #2069
-
Hello: I'm trying to use the flask-socketio with uWSGI and I get this error whenever I restart the client. I found an old discussion about this: #1797 but he's using gunicorn. My app.py: from gevent import monkey
monkey.patch_all()
from flask import Flask
from flask_socketio import SocketIO
app = Flask(__name__)
socketio = SocketIO(app, async_mode='gevent')
@app.route('/')
def index():
return 'Hello, World!'
@socketio.on('message')
def handle_message(msg):
print('Received message: ' + msg)
socketio.send('Echo: ' + msg)
if __name__ == '__main__':
socketio.run(app, debug=True) client-uwsgi.py: import socketio
# Create a Socket.IO client
# sio = socketio.Client(logger=True, engineio_logger=True, reconnection_attempts=5, reconnection_delay=1, reconnection_delay_max=5)
sio = socketio.Client(logger=True)
@sio.event
def connect():
print('Connection established')
sio.send('Hello from client!')
@sio.event
def message(data):
print('Message received from server:', data)
@sio.event
def disconnect():
print('Disconnected from server')
if __name__ == '__main__':
# Connect to the server
sio.connect('http://localhost:8000')
sio.wait() I tried the command is Client output: # python3 client-uwsgi.py
Engine.IO connection established
Namespace / is connected
Connection established
Emitting event "message" [/]
Received event "message" [/]
Message received from server: Echo: Hello from client!
It seems like the client connected successfully but the uwsgi raise the error (uwsgi output): # uwsgi --http :8000 --gevent 1000 --http-websockets --master --wsgi-file app.py --callable app
*** Starting uWSGI 2.0.26 (64bit) on [Sun Jun 23 04:26:51 2024] ***
compiled with version: 11.4.0 on 23 June 2024 03:55:12
os: Linux-5.15.0-92-generic #102-Ubuntu SMP Wed Jan 10 09:33:48 UTC 2024
nodename: static-websites-server
machine: x86_64
clock source: unix
detected number of CPU cores: 4
current working directory: /opt/flask-test
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
your processes number limit is 63801
your memory page size is 4096 bytes
detected max file descriptor number: 1048576
- async cores set to 1000 - fd table size: 1048576
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on :8000 fd 4
uwsgi socket 0 bound to TCP address 127.0.0.1:43313 (port auto-assigned) fd 3
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
Python version: 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]
Python main interpreter initialized at 0x55edb1b6f1a0
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 21036928 bytes (20543 KB) for 1000 cores
*** Operational MODE: async ***
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x55edb1b6f1a0 pid: 382562 (default app)
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 382562)
spawned uWSGI worker 1 (pid: 382563, cores: 1000)
spawned uWSGI http 1 (pid: 382564)
*** running gevent loop engine [addr:0x55edb03f8040] ***
[pid: 382563|app: 0|req: 1/1] 127.0.0.1 () {32 vars in 490 bytes} [Sun Jun 23 04:27:00 2024] GET /socket.io/?transport=polling&EIO=4&t=1719116820.8296034 => generated 97 bytes in 1 msecs (HTTP/1.1 200) 2 headers in 100 bytes (3 switches on core 999)
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1498, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python3.10/dist-packages/flask_socketio/__init__.py", line 43, in __call__
return super(_SocketIOMiddleware, self).__call__(environ,
File "/usr/local/lib/python3.10/dist-packages/engineio/middleware.py", line 63, in __call__
return self.engineio_app.handle_request(environ, start_response)
File "/usr/local/lib/python3.10/dist-packages/socketio/server.py", line 433, in handle_request
return self.eio.handle_request(environ, start_response)
File "/usr/local/lib/python3.10/dist-packages/engineio/server.py", line 274, in handle_request
packets = socket.handle_get_request(
File "/usr/local/lib/python3.10/dist-packages/engineio/socket.py", line 90, in handle_get_request
return getattr(self, '_upgrade_' + transport)(environ,
File "/usr/local/lib/python3.10/dist-packages/engineio/socket.py", line 146, in _upgrade_websocket
return ws(environ, start_response)
File "/usr/local/lib/python3.10/dist-packages/engineio/async_drivers/gevent.py", line 54, in __call__
raise RuntimeError('The gevent-websocket server is not '
RuntimeError: The gevent-websocket server is not configured appropriately. See the Deployment section of the documentation for more information.
[pid: 382563|app: 0|req: 2/2] 127.0.0.1 () {34 vars in 588 bytes} [Sun Jun 23 04:27:00 2024] GET /socket.io/?transport=websocket&EIO=4&sid=2mlY4fpb6B_7-uhLAAAA&t=1719116820.8338363 => generated 0 bytes in 30 msecs (HTTP/1.1 500) 0 headers in 0 bytes (1 switches on core 999)
[pid: 382563|app: 0|req: 3/3] 127.0.0.1 () {36 vars in 544 bytes} [Sun Jun 23 04:27:00 2024] POST /socket.io/?transport=polling&EIO=4&sid=2mlY4fpb6B_7-uhLAAAA => generated 2 bytes in 1 msecs (HTTP/1.1 200) 2 headers in 85 bytes (3 switches on core 999)
[pid: 382563|app: 0|req: 4/4] 127.0.0.1 () {32 vars in 540 bytes} [Sun Jun 23 04:27:00 2024] GET /socket.io/?transport=polling&EIO=4&sid=2mlY4fpb6B_7-uhLAAAA&t=1719116820.8659859 => generated 32 bytes in 0 msecs (HTTP/1.1 200) 2 headers in 100 bytes (3 switches on core 998)
Received message: Hello from client!
[pid: 382563|app: 0|req: 5/5] 127.0.0.1 () {36 vars in 545 bytes} [Sun Jun 23 04:27:00 2024] POST /socket.io/?transport=polling&EIO=4&sid=2mlY4fpb6B_7-uhLAAAA => generated 2 bytes in 0 msecs (HTTP/1.1 200) 2 headers in 85 bytes (3 switches on core 998)
[pid: 382563|app: 0|req: 6/6] 127.0.0.1 () {32 vars in 538 bytes} [Sun Jun 23 04:27:00 2024] GET /socket.io/?transport=polling&EIO=4&sid=2mlY4fpb6B_7-uhLAAAA&t=1719116820.870393 => generated 40 bytes in 0 msecs (HTTP/1.1 200) 2 headers in 100 bytes (3 switches on core 999)
[pid: 382563|app: 0|req: 7/7] 127.0.0.1 () {32 vars in 540 bytes} [Sun Jun 23 04:27:00 2024] GET /socket.io/?transport=polling&EIO=4&sid=2mlY4fpb6B_7-uhLAAAA&t=1719116820.8729086 => generated 1 bytes in 24964 msecs (HTTP/1.1 200) 2 headers in 100 bytes (3 switches on core 999)
[pid: 382563|app: 0|req: 9/8] 127.0.0.1 () {36 vars in 544 bytes} [Sun Jun 23 04:27:25 2024] POST /socket.io/?transport=polling&EIO=4&sid=2mlY4fpb6B_7-uhLAAAA => generated 2 bytes in 0 msecs (HTTP/1.1 200) 2 headers in 85 bytes (3 switches on core 998)
[pid: 382563|app: 0|req: 9/9] 127.0.0.1 () {32 vars in 540 bytes} [Sun Jun 23 04:27:25 2024] GET /socket.io/?transport=polling&EIO=4&sid=2mlY4fpb6B_7-uhLAAAA&t=1719116845.8397706 => generated 1 bytes in 25011 msecs (HTTP/1.1 200) 2 headers in 100 bytes (3 switches on core 999)
[pid: 382563|app: 0|req: 11/10] 127.0.0.1 () {36 vars in 544 bytes} [Sun Jun 23 04:27:50 2024] POST /socket.io/?transport=polling&EIO=4&sid=2mlY4fpb6B_7-uhLAAAA => generated 2 bytes in 0 msecs (HTTP/1.1 200) 2 headers in 85 bytes (3 switches on core 998) Or using an uWSGI config file to start it: [uwsgi]
http = :8000
http-websockets = true
master = true
gevent = 1000
wsgi-file = app.py
callable = app
processes = 1
threads = 1
buffer-size = 32768
gevent-monkey-patch = true
log-format = %(addr) - %(method) %(uri) => generated %(size) bytes in %(msecs) ms But the result is same: root@server:/opt/flask-test# uwsgi --ini flask-test-uwsgi.ini
[uWSGI] getting INI configuration from flask-test-uwsgi.ini
*** Starting uWSGI 2.0.26 (64bit) on [Sun Jun 23 04:31:07 2024] ***
compiled with version: 11.4.0 on 23 June 2024 03:55:12
os: Linux-5.15.0-92-generic #102-Ubuntu SMP Wed Jan 10 09:33:48 UTC 2024
nodename: static-websites-server
machine: x86_64
clock source: unix
detected number of CPU cores: 4
current working directory: /opt/flask-test
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
your processes number limit is 63801
your memory page size is 4096 bytes
detected max file descriptor number: 1048576
- async cores set to 1000 - fd table size: 1048576
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on :8000 fd 4
uwsgi socket 0 bound to TCP address 127.0.0.1:34429 (port auto-assigned) fd 3
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
Python version: 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]
Python main interpreter initialized at 0x558d86059090
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 78380928 bytes (76543 KB) for 1000 cores
*** Operational MODE: async ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x558d86059090 pid: 383312 (default app)
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 383312)
spawned uWSGI worker 1 (pid: 383313, cores: 1000)
spawned uWSGI http 1 (pid: 383314)
*** running gevent loop engine [addr:0x558d846ab040] ***
127.0.0.1 - GET /socket.io/?transport=polling&EIO=4&t=1719117069.240336 => generated 197 bytes in 1 ms
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1498, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python3.10/dist-packages/flask_socketio/__init__.py", line 43, in __call__
return super(_SocketIOMiddleware, self).__call__(environ,
File "/usr/local/lib/python3.10/dist-packages/engineio/middleware.py", line 63, in __call__
return self.engineio_app.handle_request(environ, start_response)
File "/usr/local/lib/python3.10/dist-packages/socketio/server.py", line 433, in handle_request
return self.eio.handle_request(environ, start_response)
File "/usr/local/lib/python3.10/dist-packages/engineio/server.py", line 274, in handle_request
packets = socket.handle_get_request(
File "/usr/local/lib/python3.10/dist-packages/engineio/socket.py", line 90, in handle_get_request
return getattr(self, '_upgrade_' + transport)(environ,
File "/usr/local/lib/python3.10/dist-packages/engineio/socket.py", line 146, in _upgrade_websocket
return ws(environ, start_response)
File "/usr/local/lib/python3.10/dist-packages/engineio/async_drivers/gevent.py", line 54, in __call__
raise RuntimeError('The gevent-websocket server is not '
RuntimeError: The gevent-websocket server is not configured appropriately. See the Deployment section of the documentation for more information.
127.0.0.1 - GET /socket.io/?transport=websocket&EIO=4&sid=zVoAullY8WPg0-bRAAAA&t=1719117069.2438295 => generated 0 bytes in 30 ms
127.0.0.1 - POST /socket.io/?transport=polling&EIO=4&sid=zVoAullY8WPg0-bRAAAA => generated 87 bytes in 0 ms
127.0.0.1 - GET /socket.io/?transport=polling&EIO=4&sid=zVoAullY8WPg0-bRAAAA&t=1719117069.2754402 => generated 132 bytes in 0 ms
Received message: Hello from client!
127.0.0.1 - POST /socket.io/?transport=polling&EIO=4&sid=zVoAullY8WPg0-bRAAAA => generated 87 bytes in 0 ms
127.0.0.1 - GET /socket.io/?transport=polling&EIO=4&sid=zVoAullY8WPg0-bRAAAA&t=1719117069.2784455 => generated 140 bytes in 0 ms |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
I'm not sure if the reason is the root. I tried to change uid and gid to uwsgi (a new user I created): [uwsgi]
http = :8000
http-websockets = true
master = true
gevent = 1000
wsgi-file = app.py
callable = app
processes = 1
threads = 1
buffer-size = 32768
; logto = ./logs/flask-test-uwsgi.logs
uid=uwsgi
gid=uwsgi
gevent-monkey-patch = true
log-format = %(addr) - %(method) %(uri) => generated %(size) bytes in %(msecs) ms But the output is same: root@static-websites-server:/opt/flask-test# uwsgi --ini flask-test-uwsgi.ini
[uWSGI] getting INI configuration from flask-test-uwsgi.ini
*** Starting uWSGI 2.0.26 (64bit) on [Sun Jun 23 04:36:30 2024] ***
compiled with version: 11.4.0 on 23 June 2024 03:55:12
os: Linux-5.15.0-92-generic #102-Ubuntu SMP Wed Jan 10 09:33:48 UTC 2024
nodename: static-websites-server
machine: x86_64
clock source: unix
detected number of CPU cores: 4
current working directory: /opt/flask-test
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
setgid() to 123
setuid() to 116
your processes number limit is 63801
your memory page size is 4096 bytes
detected max file descriptor number: 1048576
- async cores set to 1000 - fd table size: 1048576
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on :8000 fd 4
uwsgi socket 0 bound to TCP address 127.0.0.1:40361 (port auto-assigned) fd 3
Python version: 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]
Python main interpreter initialized at 0x55dde5713b90
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 78380928 bytes (76543 KB) for 1000 cores
*** Operational MODE: async ***
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x55dde5713b90 pid: 384057 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 384057)
spawned uWSGI worker 1 (pid: 384063, cores: 1000)
spawned uWSGI http 1 (pid: 384064)
*** running gevent loop engine [addr:0x55dde3c2d040] ***
127.0.0.1 - GET /socket.io/?transport=polling&EIO=4&t=1719117392.1000278 => generated 197 bytes in 1 ms
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1498, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python3.10/dist-packages/flask_socketio/__init__.py", line 43, in __call__
return super(_SocketIOMiddleware, self).__call__(environ,
File "/usr/local/lib/python3.10/dist-packages/engineio/middleware.py", line 63, in __call__
return self.engineio_app.handle_request(environ, start_response)
File "/usr/local/lib/python3.10/dist-packages/socketio/server.py", line 433, in handle_request
return self.eio.handle_request(environ, start_response)
File "/usr/local/lib/python3.10/dist-packages/engineio/server.py", line 274, in handle_request
packets = socket.handle_get_request(
File "/usr/local/lib/python3.10/dist-packages/engineio/socket.py", line 90, in handle_get_request
return getattr(self, '_upgrade_' + transport)(environ,
File "/usr/local/lib/python3.10/dist-packages/engineio/socket.py", line 146, in _upgrade_websocket
return ws(environ, start_response)
File "/usr/local/lib/python3.10/dist-packages/engineio/async_drivers/gevent.py", line 54, in __call__
raise RuntimeError('The gevent-websocket server is not '
RuntimeError: The gevent-websocket server is not configured appropriately. See the Deployment section of the documentation for more information.
127.0.0.1 - GET /socket.io/?transport=websocket&EIO=4&sid=5G_vJ_orT90hHpPeAAAA&t=1719117392.1035254 => generated 0 bytes in 29 ms
127.0.0.1 - POST /socket.io/?transport=polling&EIO=4&sid=5G_vJ_orT90hHpPeAAAA => generated 87 bytes in 0 ms
127.0.0.1 - GET /socket.io/?transport=polling&EIO=4&sid=5G_vJ_orT90hHpPeAAAA&t=1719117392.1347957 => generated 132 bytes in 0 ms
Received message: Hello from client!
127.0.0.1 - POST /socket.io/?transport=polling&EIO=4&sid=5G_vJ_orT90hHpPeAAAA => generated 87 bytes in 0 ms
127.0.0.1 - GET /socket.io/?transport=polling&EIO=4&sid=5G_vJ_orT90hHpPeAAAA&t=1719117392.137598 => generated 140 bytes in 0 ms |
Beta Was this translation helpful? Give feedback.
-
For uWSGI you have to define your SocketIO server as follows: socketio = SocketIO(app, async_mode='gevent_uwsgi') |
Beta Was this translation helpful? Give feedback.
-
@miguelgrinberg Thanks for your reply. I'll try it! |
Beta Was this translation helpful? Give feedback.
For uWSGI you have to define your SocketIO server as follows: