在 FastAPI 中更改来自 MySQL 的数据类型输入

问题描述 投票:0回答:1

我的这一行有“serialize_response”错误:

@app.get("/get-sensors/", response_model=List[Data])

还有这个:

return {"status": "success", "list": data}

我该如何解决这个问题!

我想获取字典类型的数据

python mysql json dictionary fastapi
1个回答
0
投票

您的

response_model
类型是
list[Data]
,但您正在返回
dict[str, Any]

您应该将

{"status": "success", "list": data}
更改为
return data
或将
response_model
更改为
MyResponse


class MyResponse(BaseModel):
    status: str
    list: list[Data]

@app.get("/get-sensors/", response_model=MyResponse)

© www.soinside.com 2019 - 2024. All rights reserved.