Error during WebSocket handshake: Unexpected response code: 400 (anonymous) @ (index):16
See original GitHub issueChecklist
- The bug is reproducible against the latest release and/or
master
. - There are no similar issues or pull requests to fix it yet.
Describe the bug
I am following the Fastapi websockets tutorial (https://fastapi.tiangolo.com/advanced/websockets/#await-for-messages-and-send-messages). With the exact code given (see link) I start uvicorn with uvicorn main:app --reload
visit http://127.0.0.1:8000/. I get this error in my chrome console:
(index):16 WebSocket connection to 'ws://localhost:8000/ws' failed: Error during WebSocket handshake: Unexpected response code: 400
To reproduce
Expected behavior
When I click “send” I expect to see the message I typed appear on the screen
Actual behavior
When I click “send” nothing happens
Debugging material
Environment
-
OS / Python / Uvicorn version: just run
uvicorn --version
macos 10.15.5 python 3.8.2 uvicorn 0.12.1 -
The exact command you’re running uvicorn with, all flags you passed included. If you run it with gunicorn please do the same. If there is a reverse-proxy involved and you cannot reproduce without it please give the minimal config of it to reproduce.
uvicorn main:app --reload
Additional context
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:11 (4 by maintainers)
Top GitHub Comments
Fixed it with:
pip3 install websockets
ok the new packaging does not install websocket or h11 by default so with a simple
pip install uvicorn
no ws will be handled.to fix this. install with
pip install uvicorn[standard]
.we need to either provide a gentle message on ws usage if the latter installation was used or update docs, or both