docker - 发布 FastAPI docker-container 时出现 422 Unprocessable Entity 错误,但在未 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 的路由器解析它们时明显不同?
通过适当的缩进解决了这个问题。
推荐阅读
- android - 在 Android Studio 中运行 Flutter App 时出现错误:任务 ':app:generateDebugBuildConfig' 执行失败
- javascript - 如何从 firefox 插件访问 firebase firestore?
- javascript - platform.js 还是 api.js?谷歌API
- c# - 存储动作规则
- python - 如何在熊猫中使用带移位功能的最小值/最大值?
- python - 在列表列表中查找共同元素
- javascript - 在向下滚动时显示组件中的某个元素并在向上滚动时隐藏 Reactjs
- django - 在 django 的“for”循环中使用“if”调用函数不起作用
- pine-script - tradingview pine 中的不规则交易执行顺序
- javascript - html 元素正在选择超出其范围的点击事件