gevent-socketio not using my @app.route endpoint for socketio gevent-socketio not using my @app.route endpoint for socketio flask flask

gevent-socketio not using my @app.route endpoint for socketio


The weird behavior is because of this line:

dapp = werkzeug.debug.DebuggedApplication(app, evalex = True)

Socketio and the werkzeug debugger don't work together. There is already an open issue about this see: https://github.com/abourget/gevent-socketio/issues/114

But you can work around it by making a custom debugger class.

from werkzeug.debug import DebuggedApplicationclass MyDebuggedApplication(DebuggedApplication):    def __call__(self, environ, start_response):        # check if websocket call        if "wsgi.websocket" in environ and not environ["wsgi.websocket"] is None:            # a websocket call, no debugger ;)            return self.app(environ, start_response)        # else go on with debugger        return DebuggedApplication.__call__(self, environ, start_response)# remember to call the overwritten debugger in your run_dev_server() functiondapp = MyDebuggedApplication(app, evalex = True)

The patch relies on the environment-key wsgi.websocket, which only seems to be present in websocket calls. Be careful, I haven't put much thought into that, there are might be other issues.


Took me a while, but it looks like I've solved it, enjoy:

https://github.com/Aldanor/SocketIO-Flask-Debug

In a nutshell:

  • you need to explicitly extract the values from the generator returned by werkzeug.debug.DebuggedApplication whenever a socket.io request is spotted, this enables to establish the socket connection properly
  • socket.io namespace handlers will not be covered by werkzeug by default, so you need to insert your own try catch, save the traceback if an exception is caught and then reraise it somewhere within a request context