fastapi
fastapi copied to clipboard
Websocket tutorial is insufficient: NEED "pip install websockets"
Hi, thanks for excellent framework!
I found problems in a chapter "WebSockets" in docs "Advanced User Guide".
Problem: NEED Python package "websockets"
When I run example in docs, exactly the same source code in docs, I got an error message in Chrome console below:
WebSocket connection to 'ws://localhost:8000/ws' failed: Error during WebSocket handshake: Unexpected response code: 400
Solution: Install Python package "websockets"
As I installed "websockets" by pip and run same code, the websocket server run correctly. We should add sentences like "Install 'websockets' package by pip, or other package management tools, when you run this example." to docs.
pip install websockets
Thanks! You are great!
Also confirmed solution. Thanks, @nukopy!
Had the same issue and installing websockets
fixed it. I would have expected fastapi
to raise some kind of exception (ImportError
?) if a required package is not there? :thinking:
I think so, too. Maybe this problem is from the Starlete WebSocket module. FastAPI WebSocket module is fully dependent on this.
I’ll inspect this problem and create PR!
Thank you so much!!!
Hi, thanks for excellent framework!
I found problems in a chapter "WebSockets" in docs "Advanced User Guide".
Problem: NEED Python package "websockets"
When I run example in docs, exactly the same source code in docs, I got an error message in Chrome console below:
WebSocket connection to 'ws://localhost:8000/ws' failed: Error during WebSocket handshake: Unexpected response code: 400
Solution: Install Python package "websockets"
As I installed "websockets" by pip and run same code, the websocket server run correctly. We should add sentences like "Install 'websockets' package by pip, or other package management tools, when you run this example." to docs.
pip install websockets
YOU literally saved me from getting mad from almost mad state. Thanks a LOT !!
i am still getting the same error. i've installed websocket library too. Anyone able to run the example code? I am using google chrome.
Thanks! This was solved in a recent PR and is now added to the docs :nerd_face:
https://fastapi.tiangolo.com/advanced/websockets/#install-websockets
Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs.