WARNING: Unsupported upgrade request.

See original GitHub issue
app = FastAPI()

@app.websocket("/ws")
async def websoc(websocket: WebSocket):
    await websocket.accept()
    await websocket.send_json({"msg": "Hello WebSocket"})
    await websocket.close()

When attempting to run this (using UviCorn), it starts fine

then, when i try and use my client to connect the the websocket, i get this error

Python 3.8.6 (tags/v3.8.6:db45529, Sep 23 2020, 15:52:53) [MSC v.1927 64 bit (AMD64)] on win32
>>> runfile('C:/Users/Tobi/Documents/Scripting/Mixed/Webpage/main.py', wdir='C:/Users/Tobi/Documents/Scripting/Mixed/Webpage')
INFO:     Started server process [9580]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://192.168.1.88:80 (Press CTRL+C to quit)
**WARNING:  Unsupported upgrade request.**

This is my client code, its just supposed to be a very simple test

import websocket, time

ws = websocket.create_connection("ws://192.168.1.88/ws")

while True:
    ws.recv()
    time.sleep(2)

Let me know if you can help, or if anyone else has had similar issues with this.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:9
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

111reactions
baiinsscommented, Oct 21, 2020

This error is not part of the FastAPI codebase. It appears to come from uvicorn and fastapi.WebSocket is a wrapper around starlette.websockets.WebSocket

How are you calling uvicorn for your app?

Perhaps: uvicorn/test_websocket.py or starlette/test_websocket.py might be a good place to look to see how they are configuring the tests.

As suspected, this was a uvicorn issue, not FastAPI, however, to fix this, for anyone else curious, goto terminal and type

python3 -m pip uninstall uvicorn

then

python3 -m pip install uvicorn[standard]

The original uvicorn package doesnt come with websocket support, you have to download the standard one.

82reactions
KarlCMBcommented, Oct 27, 2020

Had the same issue.

pip install websockets

did the job

Read more comments on GitHub >

github_iconTop Results From Across the Web

FastAPI (Python) Why I get "Unsupported upgrade request ...
This same issue usually seems to arise from incomplete uvicorn installations, but is usually related to websockets.
Read more >
Unsupported upgrade request. - solved - Prodigy Support
Hi, I have recently upgraded my prodigy licence from the previous version 1.10(spaCy v2) to the latest version using spaCy v3.
Read more >
If you are getting `Unsupported upgrade request error` from ...
If you are getting `Unsupported upgrade request error` from uvicorn that means you just need to pip install websockets packedge.
Read more >
tiangolo/fastapi - Gitter
I'm trying to connect to my own FastAPI websocket endpoint I just put up to test, and it's giving me bad request. WARNING:...
Read more >
otree 5 behind nginx: Unsupported upgrade request
otree 5 behind nginx: Unsupported upgrade request ... uvicorn - this does indeed seem to solve the issue, but I get the following...
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found