我的这一行有“serialize_response”错误:
@app.get("/get-sensors/", response_model=List[Data])
还有这个:
return {"status": "success", "list": data}
我该如何解决这个问题!
我想获取字典类型的数据
您的
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)