r/FastAPI • • Jan 30 '21

Question Websocket streaming {"detail":"Not Found"}

Hi everyone! I'm trying to create a websocket to stream data using this example: https://stribny.name/blog/2020/07/real-time-data-streaming-using-fastapi-and-websockets/ and I have also tried implementing the top example from here: https://fastapi.tiangolo.com/advanced/websockets/

When I do uvicorn main:app --reload all I get back from http://localhost:8000/ws is {"detail":"Not Found"}.

In the terminal after it says "application startup complete" all I get back is " 127.0.0.1:65000 - "?[1mGET /ws HTTP/1.1?[0m" ?[31m404 Not Found?[0m".

How do I debug this (I'm in debug mode but it doesn't seem to be doing anything)? Or does anyone know what the problem is? I'm on windows btw

Edit: I just tried to change uvicorn to uvicorn[standard] and pip install websockets, because I was getting "Unsupported upgrade request." but neither of those things solved my issue.

1 Upvotes

4 comments sorted by

2

u/petr31052018 Jan 30 '21

Hey! I am the author of the article.

First, can you check if your websockets URL is correct? The URL should be "ws://localhost:8000/ws", not start with "http://" like you posted here ^.

1

u/tunnelvisie Jan 30 '21

Thanks, that'll do it.

1

u/Deadly_chef Jan 30 '21

Yep, you should be using ws protocol, not http

1

u/TRIstyle Nov 10 '21

If anyone tries the tutorial and comes across this, I had the same problem. For me, the javascript that sets up the chart was throwing an error (found by right clicking->inspect->console). Solved it by replacing the script tags in the tutorial for the d3 and TimeChart dependencies with the list found here: https://huww98.github.io/TimeChart/

Overall nice tutorial.