Flask-socketio: WebSocket transport not available

Created on 23 Feb 2018  路  12Comments  路  Source: miguelgrinberg/Flask-SocketIO

Awesome library!

I'm having issues running a simple example.

I'm running this code

from flask import Flask, render_template
from flask_socketio import SocketIO, emit

app = Flask(__name__)
socketio = SocketIO(app)

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

@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)

Starting the servers throws this:

WebSocket transport not available. Install eventlet or gevent and gevent-websocket for improved performance.
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

Any ideas how to solve it?

thanks!

question

Most helpful comment

The message tells you how to solve it: Install eventlet or gevent and gevent-websocket for improved performance.. Try pip install eventlet, then rerun your application. It's that simple. :)

All 12 comments

The message tells you how to solve it: Install eventlet or gevent and gevent-websocket for improved performance.. Try pip install eventlet, then rerun your application. It's that simple. :)

pip install gevent did the trick!

error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools

----------------------------------------

Command ""c:\users\rupesh kumarappdata\localprogramspythonpython37-32python.exe" -u -c "import setuptools, tokenize;__file__='C:\Users\RUPESH~1\AppData\Local\Temp\pip-install-ofyi1f5o\gevent\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\RUPESH~1AppData\Local\Temppip-record-4bhkyoc6\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\RUPESH~1AppData\Local\Temppip-install-ofyi1f5o\gevent\

installed visual c++ 14.0

You should not need Visual Studio to install gevent, since there are wheel packages available for Windows. Try the following:

  • Upgrade pip and wheel: pip install --upgrade pip wheel
  • Try to install gevent again: pip install gevent

Hopefully that'll work!

Failed building wheel for gevent
Running setup.py clean for gevent
Failed to build gevent

error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools

----------------------------------------

Command ""c:\users\rupesh kumarappdata\localprogramspythonpython37-32python.exe" -u -c "import setuptools, tokenize;__file__='C:\Users\RUPESH~1\AppData\Local\Temp\pip-install-vlaluxm_\gevent\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\RUPESH~1AppData\Local\Temppip-record-04vbliu7\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\RUPESH~1AppData\Local\Temppip-install-vlaluxm_\gevent\

C:\Users\Rupesh Kumar\Desktopproject2project2>flask run

  • Serving Flask-SocketIO app "application.py"
  • Forcing debug mode on
  • Restarting with stat
    WebSocket transport not available. Install eventlet or gevent and gevent-websocket for improved performance.

Gevent does not have a wheel for Python 3.7 32-bit, looks like they only have one for 64-bit. If you want to use Python 3.7, then switch to the 64bit version of Python. There is a wheel for Python 3.6 32-bit as well. You can see the list of wheel packages available here

(Download Windows x86-64 executable installer) from python.org
installed 64 bit and install the all required package

C:\Users\Rupesh Kumar\Downloads\lecture5\lecture5\vote0>flask run

  • Serving Flask-SocketIO app "application.py"
  • Forcing debug mode on
  • Restarting with stat
    c:\users\rupesh kumarappdata\localprogramspythonpython37\lib\importlib_bootstrap.py:219: RuntimeWarning: greenlet.greenlet size changed, may indicate binary incompatibility. Expected 144, got 128
    return f(args, *kwds)
    c:\users\rupesh kumarappdata\localprogramspythonpython37\lib\importlib_bootstrap.py:219: RuntimeWarning: greenlet.greenlet size changed, may indicate binary incompatibility. Expected 144, got 128
    return f(args, *kwds)
    c:\users\rupesh kumarappdata\localprogramspythonpython37\lib\importlib_bootstrap.py:219: RuntimeWarning: greenlet.greenlet size changed, may indicate binary incompatibility. Expected 144, got 128
    return f(args, *kwds)
    c:\users\rupesh kumarappdata\localprogramspythonpython37\lib\importlib_bootstrap.py:219: RuntimeWarning: greenlet.greenlet size changed, may indicate binary incompatibility. Expected 144, got 128
    return f(args, *kwds)
    c:\users\rupesh kumarappdata\localprogramspythonpython37\lib\importlib_bootstrap.py:219: RuntimeWarning: greenlet.greenlet size changed, may indicate binary incompatibility. Expected 144, got 128
    return f(args, *kwds)
  • Debugger is active!
  • Debugger PIN: 289-057-821
    Traceback (most recent call last):
    File "c:\users\rupesh kumarappdata\localprogramspythonpython37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
    File "c:\users\rupesh kumarappdata\localprogramspythonpython37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
    File "C:\Users\Rupesh KumarAppData\Local\Programs\Python\Python37\Scripts\flask.exe__main__.py", line 9, in
    File "c:\users\rupesh kumarappdata\localprogramspythonpython37\lib\site-packages\flask\cli.py", line 894, in main
    cli.main(args=args, prog_name=name)
    File "c:\users\rupesh kumarappdata\localprogramspythonpython37\lib\site-packages\flask\cli.py", line 557, in main
    return super(FlaskGroup, self).main(args, *kwargs)
    File "c:\users\rupesh kumarappdata\localprogramspythonpython37\lib\site-packages\click\core.py", line 697, in main
    rv = self.invoke(ctx)
    File "c:\users\rupesh kumarappdata\localprogramspythonpython37\lib\site-packages\click\core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
    File "c:\users\rupesh kumarappdata\localprogramspythonpython37\lib\site-packages\click\core.py", line 895, in invoke
    return ctx.invoke(self.callback, *ctx.params)
    File "c:\users\rupesh kumarappdata\localprogramspythonpython37\lib\site-packages\click\core.py", line 535, in invoke
    return callback(
    args, *kwargs)
    File "c:\users\rupesh kumarappdata\localprogramspythonpython37\lib\site-packages\click\decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args[1:], *
    kwargs)
    File "c:\users\rupesh kumarappdata\localprogramspythonpython37\lib\site-packages\click\core.py", line 535, in invoke
    return callback(args, *kwargs)
    File "c:\users\rupesh kumarappdata\localprogramspythonpython37\lib\site-packages\flask_socketio\cli.py", line 72, in run
    run_server()
    File "c:\users\rupesh kumarappdata\localprogramspythonpython37\lib\site-packages\flask_socketio\cli.py", line 66, in run_server
    use_reloader=False, log_output=debugger)
    File "c:\users\rupesh kumarappdata\localprogramspythonpython37\lib\site-packages\flask_socketio__init__.py", line 544, in run
    log=log, *kwargs)
    File "c:\users\rupesh kumarappdata\localprogramspythonpython37\lib\site-packages\geventpywsgi.py", line 1441, in __init__
    StreamServer.__init__(self, listener, backlog=backlog, spawn=spawn, *
    ssl_args)
    File "c:\users\rupesh kumarappdata\localprogramspythonpython37\lib\site-packages\gevent\server.py", line 109, in __init__
    BaseServer.__init__(self, listener, handle=handle, spawn=spawn)
    File "c:\users\rupesh kumarappdata\localprogramspythonpython37\lib\site-packages\gevent\baseserver.py", line 95, in __init__
    self._stop_event = Event()
    File "src\gevent\event.py", line 163, in gevent._event.Event.__init__
    File "src\gevent\event.py", line 45, in gevent._event._AbstractLinkable.__init__
    File "src\gevent_hub_local.py", line 80, in gevent.__hub_local.get_hub_noargs
    File "c:\users\rupesh kumarappdata\localprogramspythonpython37\lib\site-packages\gevent\hub.py", line 390, in __init__
    WaitOperationsGreenlet.__init__(self, None, None)
    File "src\gevent_greenlet_primitives.py", line 42, in gevent.__greenlet_primitives.TrackedRawGreenlet.__init__
    SystemError: c:_work\4\s\objects\dictobject.c:1439: bad argument to internal function

flask.cli.NoAppException: While importing "application", an ImportError was raised:

Traceback (most recent call last):
File "c:\users\rupesh kumarappdata\localprogramspythonpython37\lib\site-packages\flask\cli.py", line 235, in locate_app
__import__(module_name)
File "C:\Users\Rupesh Kumar\Desktopproject2project2application.py", line 4, in
from flask_socketio import SocketIO, emit
ModuleNotFoundError: No module named 'flask_socketio'

this was error before pip install flask-socketio
and after install above error

This problem has been reported on gevent's bug tracker, see https://github.com/gevent/gevent/issues/1261.

I solved the example using pip3 install gevent --trusted-host pypi.org --trusted-host files.pythonhosted.org

The message tells you how to solve it: Install eventlet or gevent and gevent-websocket for improved performance.. Try pip install eventlet, then rerun your application. It's that simple. :)

when i install eventlet , it shows me the problem of DNS Label is empty

from flask_socketio import SocketIO
  File "C:\Users\Client\.conda\envs\botenv\lib\site-packages\flask_socketio\__init__.py", line 9, in <module>
    from socketio import socketio_manage
  File "C:\Users\Client\.conda\envs\botenv\lib\site-packages\socketio\__init__.py", line 9, in <module>
    from .zmq_manager import ZmqManager
  File "C:\Users\Client\.conda\envs\botenv\lib\site-packages\socketio\zmq_manager.py", line 5, in <module>
    import eventlet.green.zmq as zmq
  File "C:\Users\Client\.conda\envs\botenv\lib\site-packages\eventlet\__init__.py", line 10, in <module>
    from eventlet import convenience
  File "C:\Users\Client\.conda\envs\botenv\lib\site-packages\eventlet\convenience.py", line 7, in <module>
    from eventlet.green import socket
  File "C:\Users\Client\.conda\envs\botenv\lib\site-packages\eventlet\green\socket.py", line 21, in <module>
    from eventlet.support import greendns
  File "C:\Users\Client\.conda\envs\botenv\lib\site-packages\eventlet\support\greendns.py", line 399, in <module>
    resolver = ResolverProxy(hosts_resolver=HostsResolver())
  File "C:\Users\Client\.conda\envs\botenv\lib\site-packages\eventlet\support\greendns.py", line 313, in __init__
    self.clear()
  File "C:\Users\Client\.conda\envs\botenv\lib\site-packages\eventlet\support\greendns.py", line 316, in clear
    self._resolver = dns.resolver.Resolver(filename=self._filename)
  File "C:\Users\Client\.conda\envs\botenv\lib\site-packages\dns\resolver.py", line 543, in __init__
    self.read_registry()
  File "C:\Users\Client\.conda\envs\botenv\lib\site-packages\dns\resolver.py", line 720, in read_registry
    self._config_win32_fromkey(key, False)
  File "C:\Users\Client\.conda\envs\botenv\lib\site-packages\dns\resolver.py", line 674, in _config_win32_fromkey
    self._config_win32_domain(dom)
  File "C:\Users\Client\.conda\envs\botenv\lib\site-packages\dns\resolver.py", line 639, in _config_win32_domain
    self.domain = dns.name.from_text(str(domain))
  File "C:\Users\Client\.conda\envs\botenv\lib\site-packages\dns\name.py", line 889, in from_text
    return from_unicode(text, origin, idna_codec)
  File "C:\Users\Client\.conda\envs\botenv\lib\site-packages\dns\name.py", line 852, in from_unicode
    raise EmptyLabel
dns.name.EmptyLabel: A DNS label is empty.

@NourheneMbarek: I'm not sure what the issue is, but eventlet is having trouble initializing on your system due to a problem with the dnspython package, which is a dependency. This could be due to you having an old version of the dnspython package, or your system having bad DNS configuration stored in the registry. Try upgrading eventlet and dnspython to the latest releases to see if the problem goes away.

Was this page helpful?
0 / 5 - 0 ratings