fastapi icon indicating copy to clipboard operation
fastapi copied to clipboard

Websocket tutorial is insufficient: NEED "pip install websockets"

Open nukopy opened this issue 4 years ago • 8 comments

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

image

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

nukopy avatar Oct 05 '20 17:10 nukopy

Thanks! You are great!

oguzhancelikarslan avatar Oct 23 '20 13:10 oguzhancelikarslan

Also confirmed solution. Thanks, @nukopy!

stefnestor avatar Nov 09 '20 01:11 stefnestor

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:

akoeltringer avatar Nov 13 '20 11:11 akoeltringer

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!

nukopy avatar Nov 13 '20 11:11 nukopy

Thank you so much!!!

GussSoares avatar Apr 15 '21 02:04 GussSoares

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

image

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 !!

susmitpy avatar Jun 27 '21 15:06 susmitpy

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.

image

monir-cemit avatar Oct 04 '21 05:10 monir-cemit

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

tiangolo avatar Sep 14 '22 13:09 tiangolo

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.

github-actions[bot] avatar Sep 25 '22 00:09 github-actions[bot]