0

I want to pass in a list of the class declared in the FastAPI service, something like :

@router.post("/predict")
async def predict(json_list: List[my_class])-> dict:

And I got exception: 'my_class' object is not subscriptable

What is the correct way to pass in a list of class with FastAPI? TIA!

5
  • Does this answer your question? Commented Oct 13, 2022 at 17:04
  • What is my_class defined as? Is it actual Pydantic class? On what line does the exception get raised? It seems like you're trying to access a list index on my_class, not on json_list? Commented Oct 13, 2022 at 20:17
  • M.O. - Thanks for the link. In that way, I need to add many lists. Each for a data column. To make it simple, I even think using a str to pass in json as a str. Commented Oct 14, 2022 at 21:04
  • MatsLindh - my_class is as following: class my_class(BaseModel): is_checked: bool longitude: float latitude: float Commented Oct 14, 2022 at 21:05
  • It seems to be okay, if BaseModel was imported from pydantic and List from typing. Either this is not the line where you got the exception or you just need to save your code before executing it. Commented Oct 15, 2022 at 12:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.