Flask-socketio: WebSocket is not available, what this mean ?

Created on 2 Feb 2019  路  14Comments  路  Source: miguelgrinberg/Flask-SocketIO

I have issue with message bellow:

WARNING in __init__: Flask-SocketIO is Running under Werkzeug, WebSocket is not available.

Every running my server, always showing error. Need help

question

Most helpful comment

As I said above, reconfigure your vsproject to run the script instead of calling flask run. Then add the following at the bottom of the script:

if __name__ == '__main__':
    socketio.run(app)

All 14 comments

It means that the webserver that you are using cannot do websocket. If you want to enable the websocket transport you need to use a different web server. See the deployment section of the documentation to see your options.

Same problem here:

Flask==1.0.2
Flask-SocketIO==3.2.1
greenlet==0.4.15

When I want to run flask: flask run --no-debugger --no-reload
with environments "FLASK_APP=app" "FLASK_ENV=production" "FLASK_DEBUG=0"
terminal promotes: "WARNING in __init__: Flask-SocketIO is Running under Werkzeug, WebSocket is not available."

But when I changed to old Flask-SocketIO==3.1.2, everything goes well.

@desmondddd this is correct. The flask run command cannot be used to run on the more advanced webservers anymore. This command was broken and caused problems for some people, so I'm not supporting that way of starting the server anymore, except when using the Flask dev server, which does not have WebSocket. Use socketio.run(app) to run your eventlet or gevent web server.

@miguelgrinberg That change makes debug impossible for me.

I use vscode as my IDE. According to vscode docs, in the .vscode/launch.json(the vscode debug config file), it uses flask run to startup the flask app.

But after flask-sockerio v3.1.2, the flask app just can't be startuped in vscode debug mode. First the terminal promoted "WARNING in __init__: Flask-SocketIO is Running under Werkzeug, WebSocket is not available. Running on http://127.0.0.1:5001/ (Press CTRL+C to quit)".
But when I browsed to http://127.0.0.1:5001/, the browser showed nothing. Then I pressed ctrl+c to stop the flask app. The terminal promoted "AttributeError: module 'select' has no attribute 'poll'"

Any suggestion for how to debug in vscode?

As I said above, reconfigure your vsproject to run the script instead of calling flask run. Then add the following at the bottom of the script:

if __name__ == '__main__':
    socketio.run(app)

Yes. I added a run.py outside the flask app. And I use socketio.run(app) inside the file.

When I want to debug the flask app running on eventlet, I just added codes below to the launch.json:

    {
      "name": "Debug Flask",
      "type": "python",
      "request": "launch",
      "console": "integratedTerminal",
      "pythonPath": "${config:python.pythonPath}",
      "program": "path_to_run.py",
      "gevent": true,
      "cwd": "${workspaceFolder}",
      "args": []
    }

Everything works well.

thanks for helping @miguelgrinberg @desmondddd . Now its works 馃憤

@prakasa1904 @desmondddd I am having the same issue. Is there an example repo or a little bit more guidance on running socket.io outside of the flask app?

if __name__ == '__main__':
    socketio.run(app)

thanks for that, it's working. :)

I realize this has been closed for some time, but I'm curious - is there a way to suppress this warning? I'm using Flask's CLI decorators in order to build out some database management functions, and this warning shows up each time I run one of those commands. The thing is, I'm not actually _serving_ any content while running these, so I don't care about the warning.

When I run the app as a web server, I use socketio.run and all is well. It's just the CLI that I want to tidy up.

@haliphax the error means that there are no websocket enabled servers installed in your virtualenv. Are you running the Flask CLI on a different virtualenv than the one you use when you run the server? Normally just having eventlet or gevent-websocket installed silences this warning, even if you are running unrelated CLI commands.

Nope. Same server. It's in a docker container. It may have to do with how my app is constructed; I'm not using the factory pattern.

@haliphax Hmm. Okay, I think I see what the problem is. Do you want to write a separate issue? I'll look into it.

Will do. Thanks!

Was this page helpful?
0 / 5 - 0 ratings