question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error during WebSocket handshake: Unexpected response code: 400 (anonymous) @ (index):16

See original GitHub issue

Checklist

  • 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

12reactions
KoehlerClemcommented, Oct 5, 2020

Fixed it with: pip3 install websockets

11reactions
euri10commented, Oct 5, 2020

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

WebSocket connection failed: Error during ... - Stack Overflow
Problem solved! I just figured out how to solve the issue, but I would still like to know if this is normal behavior...
Read more >
Error during WebSocket handshake: Unexpected ... - GitHub
Solved for me. It was due to wrong socket.io address in nginx configuration, that was not matching the path using the websocket.
Read more >
Error during WebSocket handshake: Unexpected response code
Allowing Anonymous login; WebAPI 2015 R3 and WebAPI 2016 SP1. It seems to be happening after the authorization is approved.
Read more >
Error during WebSocket handshake: Unexpected response ...
WebSocket connection to 'wss://mydomain/openvidu' failed: Error during WebSocket handshake: Unexpected response code: 400 - Issues with deployment - OpenVidu.
Read more >
Websocket Connection error - WordPress.org
HI. while in admin mode i happened to go into developer tools to look at some css and noticed in console i get...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Hashnode Post

No results found