Coder Social home page Coder Social logo

Runtime Error about flask-socketio HOT 15 CLOSED

miguelgrinberg avatar miguelgrinberg commented on May 21, 2024
Runtime Error

from flask-socketio.

Comments (15)

miguelgrinberg avatar miguelgrinberg commented on May 21, 2024

How did you start the app? The error seems to indicate you are not running with the gevent-socketio server,

from flask-socketio.

Govinda-Fichtner avatar Govinda-Fichtner commented on May 21, 2024

I did start it with

(venv)govindaf@Govindas-MacBook-Pro ~/workspace/Flask-SocketIO/example (master●)$ python app.py
 * Running on http://127.0.0

from flask-socketio.

Govinda-Fichtner avatar Govinda-Fichtner commented on May 21, 2024

What really confuses me is also that in the environment there is this:

'SERVER_SOFTWARE': 'gevent/1.0 Python/2.7'

So it actually seems to use the gevent server. And also I did not change anything from the checkout repository. So I was assuming that just starting app.py should be sufficient.
Do I need to do anything else?

from flask-socketio.

miguelgrinberg avatar miguelgrinberg commented on May 21, 2024

Hmm. I cannot reproduce this. I just did an install from scratch on my Mac and the example runs perfectly fine. I'm using the MacPorts Python 2.7 for this (I could not install greenlet on the stock Python from OS X, I get compiler errors).

from flask-socketio.

Govinda-Fichtner avatar Govinda-Fichtner commented on May 21, 2024

I just looked through the things I had installed with brew. I found libevent and libev. I removed these and also removed the virtualenv that I created for the sample app. Then I reinstall the requirements.txt and now it seems to work. I am not sure how this can be related. Maybe when some gevent related stuff is compiled it got the wrong libs...

When I want to run the app with gunicorn - how would I configure and start it?

from flask-socketio.

Govinda-Fichtner avatar Govinda-Fichtner commented on May 21, 2024

Miguel, sorry that I took so much of your time when it seems it was the fault of the libs I had installed on my computer not Flask-SocketIO. I really appreciate the time and effort you put into something like Flask-SocketIO!

from flask-socketio.

miguelgrinberg avatar miguelgrinberg commented on May 21, 2024

When I want to run the app with gunicorn - how would I configure and start it?

This is in the documentation. Here is an example cmd line:

gunicorn --worker-class socketio.sgunicorn.GeventSocketIOWorker module:app

from flask-socketio.

guilhermebr avatar guilhermebr commented on May 21, 2024

It's happening the same with me:

(monitor)root@vagrant-debian-wheezy:/var/sites/ipsafe/monitor/src# python server.py
Traceback (most recent call last):
File "/var/sites/ipsafe/monitor/local/lib/python2.7/site-packages/gevent/pywsgi.py", line 508, in handle_one_response
self.run_application()
File "/var/sites/ipsafe/monitor/local/lib/python2.7/site-packages/gevent/pywsgi.py", line 494, in run_application
self.result = self.application(self.environ, self.start_response)
File "/var/sites/ipsafe/monitor/local/lib/python2.7/site-packages/flask_socketio/init.py", line 27, in call
raise RuntimeError('You need to use a gevent-socketio server.')
RuntimeError: You need to use a gevent-socketio server.
{'GATEWAY_INTERFACE': 'CGI/1.1',
'HTTP_ACCEPT': '/',
'HTTP_ACCEPT_ENCODING': 'gzip,deflate,sdch',
'HTTP_ACCEPT_LANGUAGE': 'en-US,en;q=0.8,es;q=0.6,pt;q=0.4',
'HTTP_CONNECTION': 'keep-alive',
'HTTP_COOKIE': 'InfoViewCE_SAPCnt=null; InfoViewCE_SAPSys=null; InfoViewPLATFORMSVC_COOKIE_AUTH=secEnterprise; InfoViewPLATFORMSVC_COOKIE_CMS=BO2008%3A6400; InfoViewPLATFORMSVC_COOKIE_USR=guilherme.bessa%40ipsafe.com.br; umitsessid=10eee8a64ba0d95a013d6c7f546b0f0b; __atuvc=1%7C23; session=.eJw9jr0KgzAYAF-lfLNDNaaK4GaRFhIRQiVZRD9_qqEtRKWi-O5tHTrceMetkDemHu4QjGaqLci7CoIVDiUEoOIzlQ-ulUDCl9SWPbosTuckkzPL0jcTvFOiPbIIQ9gswME0-fjS9fOfSCJNk-yntgtzeK-iC2GZdJlAqmLpKHHVXFSa97cuEe38xeFpuOemoTb7DlDiY0M9D8vSL23qFKcGsSAEtg_epTw0.Bm6JEA.o--S5Gfk9jalWlF_dhPJf8XIrQc; sessionid=jehby3nta6kni5iw65abjjawayfdpk7j; csrftoken=R9tkTmMXIiGK2CbYJPbqz73UFQEvh1BE',
'HTTP_HOST': '127.0.0.1:8080',
'HTTP_REFERER': 'http://127.0.0.1:8080/',
'HTTP_USER_AGENT': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36',
'PATH_INFO': '/socket.io/',
'QUERY_STRING': 'EIO=2&transport=polling&t=1402006999937-32',
'REMOTE_ADDR': '10.0.2.2',
'REMOTE_PORT': '60661',
'REQUEST_METHOD': 'GET',
'SCRIPT_NAME': '',
'SERVER_NAME': 'vagrant-debian-wheezy.vagrantup.com',
'SERVER_PORT': '8080',
'SERVER_PROTOCOL': 'HTTP/1.1',
'SERVER_SOFTWARE': 'gevent/1.0 Python/2.7',
'wsgi.errors': <open file '', mode 'w' at 0x7f352b46f270>,
'wsgi.input': <gevent.pywsgi.Input object at 0x1791fd0>,
'wsgi.multiprocess': False,
'wsgi.multithread': False,
'wsgi.run_once': False,
'wsgi.url_scheme': 'http',
'wsgi.version': (1, 0)} failed with RuntimeError

10.0.2.2 - - [2014-06-05 22:23:20] "GET /socket.io/?EIO=2&transport=polling&t=1402006999937-32 HTTP/1.1" 500 161 0.017343

from flask-socketio.

tito avatar tito commented on May 21, 2024

I got the same too. pip freeze (stripped):

gevent==1.0.1
gevent-socketio==0.3.6
gevent-websocket==0.9.3
greenlet==0.4.2
Flask==0.10.1
Flask-SocketIO==0.3.7

The example i'm testing:

from flask import Flask, render_template
from flask.ext.socketio import SocketIO, emit

HTML = '''
<html>
<head>
    <script src="https://cdn.socket.io/socket.io-1.0.4.js"></script>
    <script>
    var socket = io();
    </script>
</head>
<body>
Hello
</body>
</html>
'''

app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)

@app.route('/')
def index():
    return HTML

@socketio.on('my event', namespace='/test')
def test_message(message):
    emit('my response', {'data': message['data']})

@socketio.on('my broadcast event', namespace='/test')
def test_message(message):
    emit('my response', {'data': message['data']}, broadcast=True)

@socketio.on('connect', namespace='/test')
def test_connect():
    emit('my response', {'data': 'Connected'})

@socketio.on('disconnect', namespace='/test')
def test_disconnect():
    print('Client disconnected')

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

Run with python test.py:

$ python test.py
127.0.0.1 - - [2014-06-08 03:30:17] "GET / HTTP/1.1" 200 288 0.001365
Traceback (most recent call last):
  File "/home/tito/.envs/testsocketio/local/lib/python2.7/site-packages/gevent/pywsgi.py", line 508, in handle_one_response
    self.run_application()
  File "/home/tito/.envs/testsocketio/local/lib/python2.7/site-packages/gevent/pywsgi.py", line 494, in run_application
    self.result = self.application(self.environ, self.start_response)
  File "/home/tito/.envs/testsocketio/local/lib/python2.7/site-packages/flask_socketio/__init__.py", line 27, in __call__
    raise RuntimeError('You need to use a gevent-socketio server.')
RuntimeError: You need to use a gevent-socketio server.
{'GATEWAY_INTERFACE': 'CGI/1.1',
 'HTTP_ACCEPT': '*/*',
 'HTTP_ACCEPT_ENCODING': 'gzip,deflate,sdch',
 'HTTP_ACCEPT_LANGUAGE': 'en-US,en;q=0.8,fr;q=0.6',
 'HTTP_CONNECTION': 'keep-alive',
 'HTTP_COOKIE': '_pk_id.7.1fff=6d547a8ce1cb8a2c.1395234273.3.1395962904.1395304768.; csrftoken=JbCP7osa6fmUuzOXYAUE0YjVr6Wll74O; session=eyJjc3JmIjp7IiBiIjoiTWpVNFkyUm1PVFl0WkdFd05DMHhNV1V6TFdFMlpUQXRaalEyWkRBMFpEWTNaRFl6In0sInVzZXJfaWQiOnsiIGIiOiJOVE0zTVRCaVpqYzBNVEF5TmpRellqUm1ZakkxWkRrMyJ9fQ.BlKo6A.IBhrCUBdUQYhRGSg2GDTGecsarI; testsocketio_id=cf856894-4a60-986b-2462-73ad08e9fa82',
 'HTTP_HOST': 'localhost:5000',
 'HTTP_REFERER': 'http://localhost:5000/',
 'HTTP_USER_AGENT': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36',
 'PATH_INFO': '/socket.io/',
 'QUERY_STRING': 'EIO=2&transport=polling&t=1402191047419-8',
 'REMOTE_ADDR': '127.0.0.1',
 'REMOTE_PORT': '36811',
 'REQUEST_METHOD': 'GET',
 'SCRIPT_NAME': '',
 'SERVER_NAME': 'localhost',
 'SERVER_PORT': '5000',
 'SERVER_PROTOCOL': 'HTTP/1.1',
 'SERVER_SOFTWARE': 'gevent/1.0 Python/2.7',
 'wsgi.errors': <open file '<stderr>', mode 'w' at 0x7f8dcc7701e0>,
 'wsgi.input': <gevent.pywsgi.Input object at 0x2c9f150>,
 'wsgi.multiprocess': False,
 'wsgi.multithread': False,
 'wsgi.run_once': False,
 'wsgi.url_scheme': 'http',
 'wsgi.version': (1, 0)} failed with RuntimeError

And tried with gunicorn:

$ gunicorn --worker-class socketio.sgunicorn.GeventSocketIOWorker test:app
2014-06-08 03:31:11 [11457] [INFO] Starting gunicorn 18.0
2014-06-08 03:31:11 [11457] [INFO] Listening at: http://127.0.0.1:8000 (11457)
2014-06-08 03:31:11 [11457] [INFO] Using worker: socketio.sgunicorn.GeventSocketIOWorker
2014-06-08 03:31:11 [11462] [INFO] Booting worker with pid: 11462
Traceback (most recent call last):
  File "/home/tito/.envs/testsocketio/local/lib/python2.7/site-packages/gevent/pywsgi.py", line 508, in handle_one_response
    self.run_application()
  File "/home/tito/.envs/testsocketio/local/lib/python2.7/site-packages/gevent/pywsgi.py", line 494, in run_application
    self.result = self.application(self.environ, self.start_response)
  File "/home/tito/.envs/testsocketio/local/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/tito/.envs/testsocketio/local/lib/python2.7/site-packages/flask_socketio/__init__.py", line 27, in __call__
    raise RuntimeError('You need to use a gevent-socketio server.')
RuntimeError: You need to use a gevent-socketio server.
{'GATEWAY_INTERFACE': 'CGI/1.1',
 'HTTP_ACCEPT': '*/*',
 'HTTP_ACCEPT_ENCODING': 'gzip,deflate,sdch',
 'HTTP_ACCEPT_LANGUAGE': 'en-US,en;q=0.8,fr;q=0.6',
 'HTTP_CONNECTION': 'keep-alive',
 'HTTP_COOKIE': '_pk_id.7.1fff=6d547a8ce1cb8a2c.1395234273.3.1395962904.1395304768.; csrftoken=JbCP7osa6fmUuzOXYAUE0YjVr6Wll74O; session=eyJjc3JmIjp7IiBiIjoiTWpVNFkyUm1PVFl0WkdFd05DMHhNV1V6TFdFMlpUQXRaalEyWkRBMFpEWTNaRFl6In0sInVzZXJfaWQiOnsiIGIiOiJOVE0zTVRCaVpqYzBNVEF5TmpRellqUm1ZakkxWkRrMyJ9fQ.BlKo6A.IBhrCUBdUQYhRGSg2GDTGecsarI; testsocketio_id=cf856894-4a60-986b-2462-73ad08e9fa82',
 'HTTP_HOST': 'localhost:8000',
 'HTTP_REFERER': 'http://localhost:8000/',
 'HTTP_USER_AGENT': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36',
 'PATH_INFO': '/socket.io/',
 'QUERY_STRING': 'EIO=2&transport=polling&t=1402191082812-0',
 'RAW_URI': '/socket.io/?EIO=2&transport=polling&t=1402191082812-0',
 'REMOTE_ADDR': '127.0.0.1',
 'REMOTE_PORT': '35369',
 'REQUEST_METHOD': 'GET',
 'SCRIPT_NAME': '',
 'SERVER_NAME': 'localhost',
 'SERVER_PORT': '8000',
 'SERVER_PROTOCOL': 'HTTP/1.1',
 'SERVER_SOFTWARE': 'gevent/1.0 Python/2.7',
 'gunicorn.sock': <socket at 0x1607490 fileno=12 sock=127.0.0.1:8000 peer=127.0.0.1:35369>,
 'wsgi.errors': <open file '<stderr>', mode 'w' at 0x7f0aa077d1e0>,
 'wsgi.input': <gevent.pywsgi.Input object at 0x16246d0>,
 'wsgi.multiprocess': False,
 'wsgi.multithread': False,
 'wsgi.run_once': False,
 'wsgi.url_scheme': 'http',
 'wsgi.version': (1, 0)} failed with RuntimeError

from flask-socketio.

miguelgrinberg avatar miguelgrinberg commented on May 21, 2024

Please do not use the new socket.io 1.0 client libraries, that is a very recent release that is likely not supported by project gevent-socketio. Please use 0.9.16 for now.

from flask-socketio.

tito avatar tito commented on May 21, 2024

That was the issue. Using 0.9.16 client library works perfectly. Thanks!

from flask-socketio.

gu-fan avatar gu-fan commented on May 21, 2024

Met the same issue.
Addressed in this thread , Thank you

from flask-socketio.

JanBenes avatar JanBenes commented on May 21, 2024

Had the same issue with socket.io.1.1, 0.9.16 works for me

from flask-socketio.

djagdish avatar djagdish commented on May 21, 2024

After several hours of trying to debug this by wrapping the regular Flask app in different gevent supported wsgi servers, simply changing the client library to an older version solved the issue.

0.9.16 is available here: http://cdnjs.cloudflare.com/ajax/libs/socket.io/0.9.16/socket.io.min.js

from flask-socketio.

dancompton avatar dancompton commented on May 21, 2024

0.9.17 also appears to cause failure

from flask-socketio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.