We Are Going To Discuss About FastAPI – GET request results in typeerror (value is not a valid dict). So lets Start this Python Article.
FastAPI – GET request results in typeerror (value is not a valid dict)
- How to solve FastAPI – GET request results in typeerror (value is not a valid dict)
SQLAlchemy does not return a dictionary, which is what pydantic expects by default. You can configure your model to also support loading from standard orm parameters (i.e. attributes on the object instead of dictionary lookups):
class Userattribute(BaseModel): name: str value: str user_id: str id: str class Config: orm_mode = True
You can also attach a debugger right before the call toreturn
to see what's being returned.
Since this answer has become slightly popular, I'd like to also mention that you can makeorm_mode = True
the default for your schema classes by having a common parent class that inherits fromBaseModel
:class OurBaseModel(BaseModel): class Config: orm_mode = True class Userattribute(OurBaseModel): name: str value: str user_id: str id: str
This is useful if you want to supportorm_mode
for most of your classes (and for those where you don't, inherit from the regularBaseModel
). - FastAPI – GET request results in typeerror (value is not a valid dict)
SQLAlchemy does not return a dictionary, which is what pydantic expects by default. You can configure your model to also support loading from standard orm parameters (i.e. attributes on the object instead of dictionary lookups):
class Userattribute(BaseModel): name: str value: str user_id: str id: str class Config: orm_mode = True
You can also attach a debugger right before the call toreturn
to see what's being returned.
Since this answer has become slightly popular, I'd like to also mention that you can makeorm_mode = True
the default for your schema classes by having a common parent class that inherits fromBaseModel
:class OurBaseModel(BaseModel): class Config: orm_mode = True class Userattribute(OurBaseModel): name: str value: str user_id: str id: str
This is useful if you want to supportorm_mode
for most of your classes (and for those where you don't, inherit from the regularBaseModel
).
Solution 1
SQLAlchemy does not return a dictionary, which is what pydantic expects by default. You can configure your model to also support loading from standard orm parameters (i.e. attributes on the object instead of dictionary lookups):
class Userattribute(BaseModel):
name: str
value: str
user_id: str
id: str
class Config:
orm_mode = True
You can also attach a debugger right before the call to return
to see what’s being returned.
Since this answer has become slightly popular, I’d like to also mention that you can make orm_mode = True
the default for your schema classes by having a common parent class that inherits from BaseModel
:
class OurBaseModel(BaseModel):
class Config:
orm_mode = True
class Userattribute(OurBaseModel):
name: str
value: str
user_id: str
id: str
This is useful if you want to support orm_mode
for most of your classes (and for those where you don’t, inherit from the regular BaseModel
).
Original Author MatsLindh Of This Content
Conclusion
So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.