Flask-socketio: Client keeps connecting/reconnecting (400 Bad Request errors)

Created on 27 Aug 2016  路  1Comment  路  Source: miguelgrinberg/Flask-SocketIO

I've tried deploying the example listed here:
https://github.com/miguelgrinberg/Flask-SocketIO/tree/master/example

To do this, I:

  • Copied the files onto my local server
  • Set the proper owner/permissions
  • Port-forwarded port 5000
  • Set up mod_wsgi and an apache2 webserver to direct requests on port 80 to the app.py script

    • Apache webserver WSGI line: WSGIScriptAlias / /var/www/myframework/myframework.wsgi

myframework.wsgi:

#!/usr/bin/python3

import sys
sys.path.insert(0,"/var/www/myframework")

from app import app as application

However, I get errors/warnings every second as the client attempts to reconnect repeatedly:

WebSocket connection to 'ws://saveclifford.com/socket.io/?EIO=3&transport=websocket&sid=ad8c6e5f81d54560936531a6aaca4989' failed: Error during WebSocket handshake: Unexpected response code: 400
http://saveclifford.com/socket.io/?EIO=3&transport=polling&t=1472326938478-16&sid=ad8c6e5f81d54560936531a6aaca4989 Failed to load resource: the server responded with a status of 400 (BAD REQUEST)
http://saveclifford.com/socket.io/?EIO=3&transport=polling&t=1472326939117-17&sid=ad8c6e5f81d54560936531a6aaca4989 Failed to load resource: the server responded with a status of 400 (BAD REQUEST)
http://saveclifford.com/socket.io/?EIO=3&transport=polling&t=1472326942478-27&sid=baa0fce2578a4136a580f04f6adae0b6 Failed to load resource: the server responded with a status of 400 (BAD REQUEST)
socket.io.min.js:2 WebSocket connection to 'ws://saveclifford.com/socket.io/?EIO=3&transport=websocket&sid=baa0fce2578a4136a580f04f6adae0b6' failed: WebSocket is closed before the connection is established.
http://saveclifford.com/socket.io/?EIO=3&transport=polling&t=1472326942664-29&sid=baa0fce2578a4136a580f04f6adae0b6 Failed to load resource: the server responded with a status of 400 (BAD REQUEST)

This all works fine on my localhost. Please point me in the right direction.

question

Most helpful comment

Apache/mod_wsgi is not a great web server to use for Socket.IO. You are basically restricted to using a single, multithreaded worker with long-polling. WebSocket does not work to my knowledge, and using multiple workers requires sticky sessions, which I believe mod_wsgi does not support.

You should be much better off using nginx. The documentation shows an example configuration. Also look at my flack application, which includes a working nginx config.

>All comments

Apache/mod_wsgi is not a great web server to use for Socket.IO. You are basically restricted to using a single, multithreaded worker with long-polling. WebSocket does not work to my knowledge, and using multiple workers requires sticky sessions, which I believe mod_wsgi does not support.

You should be much better off using nginx. The documentation shows an example configuration. Also look at my flack application, which includes a working nginx config.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thehelpfulbees picture thehelpfulbees  路  4Comments

hrmon picture hrmon  路  5Comments

zuifengwuchou picture zuifengwuchou  路  5Comments

fbussv picture fbussv  路  4Comments

blstdmi picture blstdmi  路  3Comments