Code: Select all
from typing import Annotated
import uvicorn
from fastapi import FastAPI, Query
from pydantic import BaseModel
app = FastAPI()
class Foo(BaseModel):
bar: str
baz: dict[str, str]
@app.get("/")
def root(foo: Annotated[Foo, Query()]):
return foo
if __name__ == "__main__":
uvicorn.run("test:app")
< /code>
Ich definiere meine Abfrageparameter mit Swagger, sodass die Codierung korrekt sein sollte. Ich weiß, dass die Baz
Code: Select all
curl -X 'GET' \
'http://127.0.0.1:8000/?bar=sda&baz=%7B%22abc%22%3A%22def%22%7D' \
-H 'accept: application/json'
Code: Select all
{
"detail": [
{
"type": "dict_type",
"loc": [
"query",
"baz"
],
"msg": "Input should be a valid dictionary",
"input": "{\"abc\":\"def\"}"
}
]
}