Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

fastapi

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.

like image 239
Alex Poloz Avatar asked Jul 09 '26 22:07

Alex Poloz


2 Answers

I had this problem using java to access the api. The solution was to set HTTP Request to 1.1

var httpRequest = HttpRequest.newBuilder()
             .uri(URI.create("http://127.0.0.1:8000/jobs"))
             .version(HttpClient.Version.HTTP_1_1)
             .GET()
             .build();
like image 115
Maikel Avatar answered Jul 17 '26 09:07

Maikel


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]
like image 29
Jason Rebelo Neves Avatar answered Jul 17 '26 09:07

Jason Rebelo Neves



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!