FastAPI Why i get Unsupported upgrade request with DELETE request?

I have written a fastapi backend.
To keep the code clean I wanted to uninstall everything that was installed via pip during development and then only install the most necessary. After I did that, one endpoint doesn’t seem to work anymore.

One of the endpoints worked perfectly before. Now problems arise. Using curl or the FastAPI’s /docs page the endpoint seems to work, but when my other Java service accesses FastAPI I get the following error:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>WARNING: Unsupported upgrade request.
WARNING: No supported WebSocket library detected. Please use "pip install 'uvicorn[standard]'", or install 'websockets' or 'wsproto' manually.
INFO: 127.0.0.1:52852 - "DELETE /delete-file/ HTTP/1.1" 422 Unprocessable Entity
</code>
<code>WARNING: Unsupported upgrade request. WARNING: No supported WebSocket library detected. Please use "pip install 'uvicorn[standard]'", or install 'websockets' or 'wsproto' manually. INFO: 127.0.0.1:52852 - "DELETE /delete-file/ HTTP/1.1" 422 Unprocessable Entity </code>
WARNING:  Unsupported upgrade request.
WARNING:  No supported WebSocket library detected. Please use "pip install 'uvicorn[standard]'", or install 'websockets' or 'wsproto' manually.
INFO:     127.0.0.1:52852 - "DELETE /delete-file/ HTTP/1.1" 422 Unprocessable Entity

uvicorn is already installed and I don’t use a websocket.

I have output the request body in java:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>2024-07-15 19:15:14 Request Body: {"host":"http://localhost:9200","index":"rag-embeddings","fileEntryId":41818}
</code>
<code>2024-07-15 19:15:14 Request Body: {"host":"http://localhost:9200","index":"rag-embeddings","fileEntryId":41818} </code>
2024-07-15 19:15:14 Request Body: {"host":"http://localhost:9200","index":"rag-embeddings","fileEntryId":41818}

And I get the following error message in java:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>2024-07-15 19:15:14 Failed to delete file entry: {"detail":[{"type":"missing","loc":["body"],"msg":"Field required","input":null}]}
</code>
<code>2024-07-15 19:15:14 Failed to delete file entry: {"detail":[{"type":"missing","loc":["body"],"msg":"Field required","input":null}]} </code>
2024-07-15 19:15:14 Failed to delete file entry: {"detail":[{"type":"missing","loc":["body"],"msg":"Field required","input":null}]}

Here is the endpoint:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>class Metadata(BaseModel):
host: str
index: str
fileEntryId: int
@app.delete("/delete-file/")
async def delete_file(request: Metadata):
print(f"Received request: {request}")
...
</code>
<code>class Metadata(BaseModel): host: str index: str fileEntryId: int @app.delete("/delete-file/") async def delete_file(request: Metadata): print(f"Received request: {request}") ... </code>
class Metadata(BaseModel):
    host: str
    index: str
    fileEntryId: int


@app.delete("/delete-file/")
async def delete_file(request: Metadata):
    print(f"Received request: {request}")
    ...

Here are the package Versions:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>uvicorn==0.30.1
fastapi==0.110.2
fastapi-cli==0.0.4
pydantic==2.7.1
pydantic_core==2.18.2
</code>
<code>uvicorn==0.30.1 fastapi==0.110.2 fastapi-cli==0.0.4 pydantic==2.7.1 pydantic_core==2.18.2 </code>
uvicorn==0.30.1
fastapi==0.110.2
fastapi-cli==0.0.4
pydantic==2.7.1
pydantic_core==2.18.2

I tried to uninstall uvicorn and install ‘uvicorn[standard]’ but the problem stays the same.

3

I’m not sure that the issue is with the delete method. Most probably warning related to other methods that wait for socket connections. Here is reproducible example:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Metadata(BaseModel):
host: str
index: str
fileEntryId: int
@app.delete("/delete-file")
async def delete_file(request: Metadata):
print(f"Received request: {request}")
</code>
<code>from fastapi import FastAPI from pydantic import BaseModel app = FastAPI() class Metadata(BaseModel): host: str index: str fileEntryId: int @app.delete("/delete-file") async def delete_file(request: Metadata): print(f"Received request: {request}") </code>
from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI()

class Metadata(BaseModel):
    host: str
    index: str
    fileEntryId: int

@app.delete("/delete-file")
async def delete_file(request: Metadata):
    print(f"Received request: {request}")

run the server with:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>uvicorn app:app
</code>
<code>uvicorn app:app </code>
uvicorn app:app

Run the client with:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import requests
data = {
"host": '23423',
"index": "geek",
"fileEntryId": 3
}
requests.delete("http://localhost:8000/delete-file",
json=data)
</code>
<code>import requests data = { "host": '23423', "index": "geek", "fileEntryId": 3 } requests.delete("http://localhost:8000/delete-file", json=data) </code>
import requests

data = {
    "host": '23423',
    "index": "geek",
    "fileEntryId": 3
}

requests.delete("http://localhost:8000/delete-file", 
                json=data)

Outputs:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>INFO: Started server process [91789]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
Received request: host='23423' index='geek' fileEntryId=3
INFO: 127.0.0.1:64390 - "DELETE /delete-file HTTP/1.1" 200 OK
</code>
<code>INFO: Started server process [91789] INFO: Waiting for application startup. INFO: Application startup complete. INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) Received request: host='23423' index='geek' fileEntryId=3 INFO: 127.0.0.1:64390 - "DELETE /delete-file HTTP/1.1" 200 OK </code>
INFO:     Started server process [91789]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
Received request: host='23423' index='geek' fileEntryId=3
INFO:     127.0.0.1:64390 - "DELETE /delete-file HTTP/1.1" 200 OK

As you can see there is nothing related to websockets upgrade.

However, in any case it is worth installing websockets with pip as it is suggested in the warning message, it wouldn’t harm the project. Run:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>pip install websockets
</code>
<code>pip install websockets </code>
pip install websockets

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật