Flask-socketio: 400 Bad request while running project using eventlet or gevent

Created on 18 Jun 2020  路  9Comments  路  Source: miguelgrinberg/Flask-SocketIO

Hi , i have been using flask-socketio in my flask app.
Everything was working fine but when i install eventlet or gevent my socket connection keep getting 400 bad request error.

/socket.io/?EIO=3&transport=polling&t=NB7JIHU&sid=8270f6da526d475aafdb7b319221fe1c
Status Code: 400 BAD REQUEST

I am starting my app using socketio = SocketIO(app,cors_allowed_origins="*").

If i uninstall both eventlet and gevent it starts working fine.

question

Most helpful comment

Try:

io.connect(ptyUrl, { perMessageDeflate : false });

The setting that you used is for compression in long-polling requests. This is for WebSocket.

All 9 comments

Getting these error after enabling engineio_logger=True.

I got this error only once.

[18/Jun/2020 12:13:01] "POST /socket.io/?EIO=3&transport=polling&t=NB7MBmL&sid=7912e69c4f024113b52458a6ad9ecf16 HTTP/1.1" 200 226 1.006969[54/1849]Traceback (most recent call last):
  File "/home/ubuntu/flask_project/project/asingh/lib/python3.6/site-packages/eventlet/wsgi.py", line 566, in handle_one_response
    result = self.application(self.environ, start_response)
  File "/home/ubuntu/flask_project/project/asingh/lib/python3.6/site-packages/flask/app.py", line 2464, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/ubuntu/flask_project/project/asingh/lib/python3.6/site-packages/flask_socketio/__init__.py", line 46, in __call__
    start_response)
  File "/home/ubuntu/flask_project/project/asingh/lib/python3.6/site-packages/engineio/middleware.py", line 60, in __call__
    return self.engineio_app.handle_request(environ, start_response)
  File "/home/ubuntu/flask_project/project/asingh/lib/python3.6/site-packages/socketio/server.py", line 558, in handle_request
    return self.eio.handle_request(environ, start_response)
  File "/home/ubuntu/flask_project/project/asingh/lib/python3.6/site-packages/engineio/server.py", line 377, in handle_request
    environ, start_response)
  File "/home/ubuntu/flask_project/project/asingh/lib/python3.6/site-packages/engineio/socket.py", line 108, in handle_get_request
    start_response)
  File "/home/ubuntu/flask_project/project/asingh/lib/python3.6/site-packages/engineio/socket.py", line 152, in _upgrade_websocket
    return ws(environ, start_response)
  File "/home/ubuntu/flask_project/project/asingh/lib/python3.6/site-packages/engineio/async_drivers/eventlet.py", line 20, in __call__
    return super(WebSocketWSGI, self).__call__(environ, start_response)
  File "/home/ubuntu/flask_project/project/asingh/lib/python3.6/site-packages/eventlet/websocket.py", line 130, in __call__
    self.handler(ws)
  File "/home/ubuntu/flask_project/project/asingh/lib/python3.6/site-packages/engineio/socket.py", line 178, in _websocket_handler
    pkt = ws.wait()
  File "/home/ubuntu/flask_project/project/asingh/lib/python3.6/site-packages/eventlet/websocket.py", line 788, in wait
    for i in self.iterator:
  File "/home/ubuntu/flask_project/project/asingh/lib/python3.6/site-packages/eventlet/websocket.py", line 652, in _iter_frames
    data = fragmented_message.getvalue()
  File "/home/ubuntu/flask_project/project/asingh/lib/python3.6/site-packages/eventlet/websocket.py", line 599, in getvalue
    data = self.decompressor.decompress(data + b'\x00\x00\xff\xff')
zlib.error: Error -3 while decompressing data: invalid stored block lengths

This error keeps coming up
Screenshot (57)

Can you show me the code in the client that connects to the server? The error comes from what appears to be invalid or unsupported compression in the WebSocket connection. If your client allows you to disable WebSocket compression give that a try.

I am running client using this let socket = io.connect(ptyUrl)

Okay, so this is the JavaScript client? What version of it and what browser are you using? As I suggested before, try disabling websocket compression to see if that helps.

Yes, it is javascript client and version is socket.io-1.4.5.
I tried using with diabling websocket compression but still no luck io.connect(ptyUrl, { httpCompression : false});

Try:

io.connect(ptyUrl, { perMessageDeflate : false });

The setting that you used is for compression in long-polling requests. This is for WebSocket.

Still getting error.
image

I am using flask-socketio with this terminal package.

https://github.com/cs01/pyxtermjs

Do u think it may be causing the problem with eventlet and gevent?

@schrovski it might. If it does anything with sub-processes then it will have to be super careful to not block the eventlet/gevent loop.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

EndenDragon picture EndenDragon  路  3Comments

zuifengwuchou picture zuifengwuchou  路  5Comments

ypperlig picture ypperlig  路  5Comments

Qinusty picture Qinusty  路  3Comments

nayebare picture nayebare  路  4Comments