422 Unprocessable Entity error when POSTing a FastAPI docker-container but works when it's not dockerized

Viewed 477

With the same body and configurations, the docker container shows a 422 error. However, if I run the same FastAPI service on my PC (without Docker), I can successfully get my results.

Postman throws the following error when pinging the container:

{
    "detail": [
        {
            "loc": [
                "body"
            ],
            "msg": "value is not a valid dict",
            "type": "type_error.dict"
        }
    ]
}

For reference, this is the function in conflict:

 @router.post("/get_NERs")
 def get_NERs(self, artrel: ArticleRelevance):
     return artrel.dict()

Where ArticleRelevance is:

class ArticleRelevance(BaseModel):
    title: str
    comments: List[str]

I am successfully able to ping GET functions from the same docker container so I know the routing isn't an issue.

1 Answers

Indentations are a funny concept.

{
  "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."]
}

AND

{
      "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."]
}

are apparently different when FastAPI's router parses them?

Fixed the issue by proper indentations.

Related