3

I've got a Flask server with Flask-SocketIO to do instant reloads on some pages. Now I'm getting this message in the console: The WebSocket transport is not available, you must install a WebSocket server that is compatible with your async mode to enable it. See the documentation for details.

Like discribed here https://github.com/miguelgrinberg/Flask-SocketIO/issues/647 I tried to install gevent or eventlet, but neither one changed anything. The code on the Client is like this:

import { io } from "https://cdn.socket.io/4.4.1/socket.io.esm.min.js";
var socket = io();
socket.emit(event,data,(response) => {response_func(response);})

On the Server:

@socketio.on(event)
def functionOnEvent(data):
    functions(data)
    return data

Both code samples are of course simplified, but there is no async call of any sort.

Update:

After installing eventlet again and manually setting the async_mode the message disappeared. But now I get the following error from eventlet:

ERROR:Error on request:
Traceback (most recent call last):
File "C:\...\venv\lib\site-packages\werkzeug\serving.py", line 319, in run_wsgi
execute(self.server.app)
File "C:\...\venv\lib\site-packages\werkzeug\serving.py", line 306, in execute
application_iter = app(environ, start_response)
File "C:\...\venv\lib\site-packages\flask\app.py", line 2095, in __call__
return self.wsgi_app(environ, start_response)
File "C:\...\venv\lib\site-packages\flask_socketio\__init__.py", line 43, in __call__
return super(_SocketIOMiddleware, self).__call__(environ,
File "C:\...\venv\lib\site-packages\engineio\middleware.py", line 63, in __call__
return self.engineio_app.handle_request(environ, start_response)
File "C:\...\venv\lib\site-packages\socketio\server.py", line 597, in handle_request
return self.eio.handle_request(environ, start_response)
File "C:\...\venv\lib\site-packages\engineio\server.py", line 411, in handle_request
packets = socket.handle_get_request(
File "C:\...\venv\lib\site-packages\engineio\socket.py", line 103, in handle_get_request
return getattr(self, '_upgrade_' + transport)(environ,
File "C:\...\venv\lib\site-packages\engineio\socket.py", line 158, in _upgrade_websocket
return ws(environ, start_response)
File "C:\...\venv\lib\site-packages\engineio\async_drivers\eventlet.py", line 16, in __call__
raise RuntimeError('You need to use the eventlet server. '
RuntimeError: You need to use the eventlet server. See the Deployment section of the documentation for more information.

As far as I unterstand and show in this example https://github.com/miguelgrinberg/Flask-SocketIO-Chat I thought when running the app like socketio.run(app), it should automatically run an eventlet server?

  • The error message is very clear. You have to install a websocket server that is compatible with your async mode. What async mode are you using? You didn't say in your question. – Miguel Grinberg Apr 18 '22 at 22:13
  • I'm using no async mode. The Code above is all I'm using for the connection between Server and Client. That's the reason I don't understand the error – Dominic Meyer Apr 20 '22 at 04:23
  • 1
    Wether you know it or not, you are using an async mode. This is not optional, if you don't pick one, it is selected for you based on the packages that you have installed in your virtual environment. Review the `async_mode` parameter in the [documentation](https://flask-socketio.readthedocs.io/en/latest/api.html#flask_socketio.SocketIO). – Miguel Grinberg Apr 20 '22 at 14:06
  • Thanks, after installing eventlet again and manually setting the async_mode to eventlet the error disappeared. But now I've got an error from eventlet (updated above). – Dominic Meyer Apr 20 '22 at 18:31
  • What command do you use to start the server? Your stack trace shows that you are using Werkzeug, not eventlet. – Miguel Grinberg Apr 20 '22 at 23:11
  • At the moment I'm still in development, so I'm running it from within VSC. The Configuration is like this: {"name": "Python: Flask", "type": "python", "request": "launch", "module": "flask", "env": {"FLASK_APP": "start.py", "FLASK_ENV": "development" }, "args": [ "run", "--no-debugger" ], "jinja": true, "justMyCode": true } – Dominic Meyer Apr 21 '22 at 05:59
  • Right. So you aren't running `socketio.run()`, you are using `flask run` which starts the Werkzeug web server. Try running your main Python file from the CLI and see if that helps. You will need to modify your VSC configuration to do this. – Miguel Grinberg Apr 21 '22 at 10:26
  • After just running the app like a normal python file without the flask configuration it worked! Thanks a lot and keep up the great work – Dominic Meyer Apr 21 '22 at 19:38

0 Answers0