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:
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:
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:
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:
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:
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:
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:
uvicorn app:app
Run the client with:
import requests
data = {
"host": '23423',
"index": "geek",
"fileEntryId": 3
}
requests.delete("http://localhost:8000/delete-file",
json=data)
Outputs:
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:
pip install websockets