miguelgrinberg / Flask-SocketIO

Socket.IO integration for Flask applications.
MIT License
5.36k stars 891 forks source link

WebSocket transport not available #647

Closed cvalenzuela closed 6 years ago

cvalenzuela commented 6 years ago

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!

miguelgrinberg commented 6 years ago

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. :)

cvalenzuela commented 6 years ago

pip install gevent did the trick!

rupesh2017 commented 6 years ago

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 kumar\appdata\local\programs\python\python37-32\python.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~1\AppData\Local\Temp\pip-record-4bhkyoc6\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\RUPESH~1\AppData\Local\Temp\pip-install-ofyi1f5o\gevent\

installed visual c++ 14.0

miguelgrinberg commented 6 years ago

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

Hopefully that'll work!

rupesh2017 commented 6 years ago

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 kumar\appdata\local\programs\python\python37-32\python.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~1\AppData\Local\Temp\pip-record-04vbliu7\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\RUPESH~1\AppData\Local\Temp\pip-install-vlaluxm\gevent\

C:\Users\Rupesh Kumar\Desktop\project2\project2>flask run

miguelgrinberg commented 6 years ago

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

rupesh2017 commented 6 years ago

(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

rupesh2017 commented 6 years ago

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

Traceback (most recent call last): File "c:\users\rupesh kumar\appdata\local\programs\python\python37\lib\site-packages\flask\cli.py", line 235, in locate_app import(module_name) File "C:\Users\Rupesh Kumar\Desktop\project2\project2\application.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

miguelgrinberg commented 6 years ago

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

TailaneBrito commented 4 years ago

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

NourheneMbarek commented 4 years ago

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.
miguelgrinberg commented 4 years ago

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

Sebastian-Nielsen commented 2 years ago

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. :)

I did that but I still get the "warning":

The WebSocket transport is not available, you must install a WebSocket server that is compatible with your async mod e to enable it.

This is my requirements.txt:

aniso8601==9.0.1
argon2-cffi==21.1.0
attrs==21.2.0
backcall==0.2.0
beautifulsoup4==4.9.3
bidict==0.21.4
bleach==4.1.0
bs4==0.0.1
certifi==2020.12.5
cffi==1.14.6
chardet==4.0.0
click==7.1.2
colorama==0.4.4
configparser==5.0.2
crayons==0.4.0
cssselect2==0.4.1
cycler==0.11.0
debugpy==1.4.1
decorator==5.0.9
defusedxml==0.7.1
dnspython==1.16.0
entrypoints==0.3
eventlet==0.33.0
fake-useragent==0.1.11
Flask==1.1.2
Flask-Cors==3.0.10
Flask-RESTful==0.3.8
Flask-SocketIO==5.1.1
gevent==21.12.0
gevent-websocket==0.10.1
greenlet==1.1.2
gunicorn==20.1.0
idna==2.10
ipykernel==6.3.1
ipython==7.27.0
ipython-genutils==0.2.0
ipywidgets==7.6.4
itsdangerous==1.1.0
jedi==0.18.0
Jinja2==2.11.3
joblib==1.1.0
jsonschema==3.2.0
jupyter==1.0.0
jupyter-client==7.0.2
jupyter-console==6.4.0
jupyter-core==4.7.1
jupyterlab-pygments==0.1.2
jupyterlab-widgets==1.0.1
kiwisolver==1.3.2
lxml==4.6.2
MarkupSafe==1.1.1
matplotlib==3.4.3
matplotlib-inline==0.1.2
mistune==0.8.4
nbclient==0.5.4
nbconvert==6.1.0
nbformat==5.1.3
nest-asyncio==1.5.1
notebook==6.4.3
numpy==1.20.1
packaging==21.0
pandas==1.3.4
pandocfilters==1.4.3
parso==0.8.2
passlib==1.7.4
pickleshare==0.7.5
Pillow==8.1.2
prometheus-client==0.11.0
prompt-toolkit==3.0.20
pycparser==2.20
Pygments==2.10.0
pyimgur==0.6.0
pymongo==3.11.3
pyparsing==2.4.7
PyPDF2==1.26.0
pyperclip==1.8.2
pyrsistent==0.18.0
python-dateutil==2.8.2
python-engineio==4.3.1
python-placeholder==0.2
python-snappy==0.6.0
python-socketio==5.5.1
pytz==2021.1
pyzmq==22.2.1
qtconsole==5.1.1
QtPy==1.11.0
reportlab==3.5.66
requests==2.25.1
scikit-learn==1.0.1
scipy==1.7.2
selenium==3.141.0
Send2Trash==1.8.0
six==1.16.0
sklearn==0.0
soupsieve==2.2.1
svglib==1.0.1
terminado==0.11.1
testpath==0.5.0
threadpoolctl==3.0.0
tinycss2==1.1.0
tornado==6.1
traitlets==5.1.0
undetected-chromedriver==2.2.1
urllib3==1.26.4
wcwidth==0.2.5
webdriver-manager==3.3.0
webencodings==0.5.1
Werkzeug==1.0.1
widgetsnbextension==3.5.1
zope.event==4.5.0
zope.interface==5.4.0

Any idea as to why the error persists even after installing the said packages?

miguelgrinberg commented 2 years ago

@Sebastian-Nielsen the key is in the part that says that is compatible with your async mode. You haven't mentioned what is the async mode that you are using. Also, just so that this is clear, installing both gevent and eventlet doesn't really serve any purpose, these are two async frameworks. You would be using only one of them, or maybe none according to your chosen async mode.