-
First Check
Commit to Help
Example Codefrom typing import Annotated
from fastapi import FastAPI, Form
from pydantic import Json, BaseModel
app = FastAPI()
class JsonListModel(BaseModel):
json_list: Json[list[str]]
@app.post("/working")
async def working(json_list: Annotated[str, Form()]) -> list[str]:
model = JsonListModel(json_list=json_list)
return model.json_list
@app.post("/broken")
async def broken(json_list: Annotated[Json[list[str]], Form()] ) -> list[str]:
return json_listDescriptionIn the example code above, I would expect {"detail":[{"loc":["body","json_list"],"msg":"JSON object must be str, bytes or bytearray","type":"type_error.json"}]}Operating SystemLinux Operating System DetailsNo response FastAPI Version0.95.0 Python VersionPython 3.10.8 Additional Contextsample request that fails with import requests
import json
headers = {"Content-Type": "application/x-www-form-urlencoded"}
response = requests.post(
"http://0.0.0.0:8000/broken",
data={"json_list": json.dumps(["abc", "def"])},
headers=headers,
) |
Beta Was this translation helpful? Give feedback.
Answered by
Kludex
Jan 21, 2024
Replies: 1 comment
-
|
I've created #10997 from this discussion. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Kludex
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've created #10997 from this discussion.