miguelgrinberg / flask-sock

Modern WebSocket support for Flask.
MIT License
274 stars 24 forks source link

Example Error #5

Closed jacektrocinski closed 3 years ago

jacektrocinski commented 3 years ago

The example code does not work.

I have tried running the code in the example folder and have received the following error:

Firefox can’t establish a connection to the server at ws://localhost:5000/echo.

However, the following command does work:

wscat --connect ws://localhost:5000/echo

I have installed the following Python packages:

$ pip freeze
click==8.0.0
colorama==0.4.4
Flask==2.0.0
flask-sock==0.3.0
h11==0.12.0
itsdangerous==2.0.0
Jinja2==3.0.0
MarkupSafe==2.0.0
simple-websocket==0.2.0
Werkzeug==2.0.0
wsproto==1.0.0
miguelgrinberg commented 3 years ago

What did you type in the address bar in Firefox? You should use http://localhost:5000, since you are requesting a web page. The JavaScript code in this application will make the WebSocket connection.

jacektrocinski commented 3 years ago

Yes, that is what I did, you can see the error here:

image

Here are the exact steps to reproduce the issue, in the example folder:

$ py -m venv venv
$ py -m pip install flask
$ py -m pip install flask_sock
$ py -m pip install "werkzeug>=2.0.0rc3"
$ FLASK_APP="echo.py" flask run
 * Serving Flask app "echo.py"
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [17/May/2021 16:46:08] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [17/May/2021 16:46:08] "GET /echo HTTP/1.1" 400 -
miguelgrinberg commented 3 years ago

Okay, thanks. I've found the problem, it is a bug in the Werkzeug changes I contributed. See https://github.com/pallets/werkzeug/issues/2131.

I'll work on a fix.

jacektrocinski commented 3 years ago

Ok, thanks Miguel.

miguelgrinberg commented 3 years ago

A fix for this issue has been committed to Werkzeug towards the 2.0.2 release. You can verify the fix by installing Werkzeug's 2.0.x branch (or wait until a new release is made).

jacektrocinski commented 3 years ago

Confirmed, installed the 2.0.x branch and it is working, thanks!

py -m pip install -U https://github.com/pallets/werkzeug/archive/2.0.x.tar.gz