发布 FastAPI docker 容器时出现 422 Unprocessable Entity 错误,但在未 dockerized 时有效
422 Unprocessable Entity error when POSTing a FastAPI docker-container but works when it's not dockerized
具有相同的主体和配置,docker 容器显示 422 错误。
但是,如果我 运行 在我的 PC 上使用相同的 FastAPI 服务(没有 Docker),我可以成功获得我的结果。
Postman 在 ping 容器时抛出以下错误:
{
"detail": [
{
"loc": [
"body"
],
"msg": "value is not a valid dict",
"type": "type_error.dict"
}
]
}
供参考,这是冲突的功能:
@router.post("/get_NERs")
def get_NERs(self, artrel: ArticleRelevance):
return artrel.dict()
其中 ArticleRelevance 是:
class ArticleRelevance(BaseModel):
title: str
comments: List[str]
我成功地从同一个 docker 容器中 ping GET 函数,所以我知道路由不是问题。
缩进是一个有趣的概念。
{
"headline": "Richest nations agree to end support for coal production overseas",
"all_comments": ["Great, up next let’s shut down call centers in India", "Hope this hurts us here in Australia."]
}
和
{
"headline": "Richest nations agree to end support for coal production overseas",
"all_comments": ["Great, up next let’s shut down call centers in India", "Hope this hurts us here in Australia."]
}
当 FastAPI 的路由器解析它们时明显不同?
通过适当的缩进解决了这个问题。
具有相同的主体和配置,docker 容器显示 422 错误。 但是,如果我 运行 在我的 PC 上使用相同的 FastAPI 服务(没有 Docker),我可以成功获得我的结果。
Postman 在 ping 容器时抛出以下错误:
{
"detail": [
{
"loc": [
"body"
],
"msg": "value is not a valid dict",
"type": "type_error.dict"
}
]
}
供参考,这是冲突的功能:
@router.post("/get_NERs")
def get_NERs(self, artrel: ArticleRelevance):
return artrel.dict()
其中 ArticleRelevance 是:
class ArticleRelevance(BaseModel):
title: str
comments: List[str]
我成功地从同一个 docker 容器中 ping GET 函数,所以我知道路由不是问题。
缩进是一个有趣的概念。
{
"headline": "Richest nations agree to end support for coal production overseas",
"all_comments": ["Great, up next let’s shut down call centers in India", "Hope this hurts us here in Australia."]
}
和
{
"headline": "Richest nations agree to end support for coal production overseas",
"all_comments": ["Great, up next let’s shut down call centers in India", "Hope this hurts us here in Australia."]
}
当 FastAPI 的路由器解析它们时明显不同?
通过适当的缩进解决了这个问题。