pythonfastapi

FastAPI (Python) Why I get "Unsupported upgrade request." with POST request?


I have similar apps on Flask and FastAPI. When I do this curl requests with Flask, that is all right:

Without TLS:

curl -X POST -H "Content-Type: application/json" -d '{"method": "account.auth"}' http://X.X.X.X:5050/

{"error":0,"result":{"token":"XXX"}}

With TLS:

curl -X POST -H "Content-Type: application/json" -d '{"method": "account.auth"}' https://example.com:8443/api/

{"error":0,"result":{"token":"XXX"}}

!!! But with FastAPI I get another result:

Without TLS:

curl -X POST -H "Content-Type: application/json" -d '{"method": "account.auth"}' http://X.X.X.X:5050/

{"error":0,"result":{"token":"XXX"}}

With TLS:

curl -X POST -H "Content-Type: application/json" -d '{"method": "account.auth"}' https://example.com:8443/api/

Unsupported upgrade request.

How to fix problem with "Unsupported upgrade request."? And what is it? Flask are working with it normally.


Solution

  • This same issue usually seems to arise from incomplete uvicorn installations, but is usually related to websockets.

    A solution for this issue might be to reinstall uvicorn with the recommended (by FastAPI) extras:

    python3 -m pip uninstall uvicorn
    python3 -m pip install uvicorn[standard]