FastAPI请求中的不可散列类型

问题描述

我正在使用fastapi编写post-api。所需的请求格式为:

{
   "leadid":LD123,"parties":[
      {
         "uid":123123,"cust_name":"JOhn Doe",},...]}

python中的fastapi代码为:

class Customer(BaseModel):
    UID: str
    CustName: str

class PackageIn(BaseModel): 
    lead_id: str
    parties: Set[Customer]
    # threshold: Optional[int] = 85

app = FastAPI()

@app.post('/')
async def nm_v2(package:PackageIn):
    return {"resp":"Response"}

当我访问SwaggerUI提交响应时,错误为“ 422错误:无法处理的实体” 。另外,SwaggerUI文档指出

{
  "detail": [
    {
      "loc": [
        "body"
      ],"msg": "unhashable type: 'Customer'","type": "type_error"
    }
  ]
}

我不知道如何在不创建一个单独的基于pydantic的类Customer的情况下为请求有效负载创建此dict()结构。请告诉我如何纠正错误。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)