pydantic.error_wrappers.ValidationError: 1 validation error for B

We Are Going To Discuss About pydantic.error_wrappers.ValidationError: 1 validation error for B. So lets Start this Python Article.

pydantic.error_wrappers.ValidationError: 1 validation error for B

  1. How to solve pydantic.error_wrappers.ValidationError: 1 validation error for B

    Oh, it was so simple… instead of using a dict type, just use the model A, which already matches the subobject.
    from pydantic import BaseModel, Field class A(BaseModel): a: str = Field(None, alias="А") class B(BaseModel): b: A = Field(None, alias="Б") j = { "Б": { "А": "Значение" } } obj = B.parse_obj(j) print(obj.json())

  2. pydantic.error_wrappers.ValidationError: 1 validation error for B

    Oh, it was so simple… instead of using a dict type, just use the model A, which already matches the subobject.
    from pydantic import BaseModel, Field class A(BaseModel): a: str = Field(None, alias="А") class B(BaseModel): b: A = Field(None, alias="Б") j = { "Б": { "А": "Значение" } } obj = B.parse_obj(j) print(obj.json())

Solution 1

Oh, it was so simple… instead of using a dict type, just use the model A, which already matches the subobject.

from pydantic import BaseModel, Field


class A(BaseModel):
    a: str = Field(None, alias="А")


class B(BaseModel):
    b: A = Field(None, alias="Б")


j = {
    "Б": {
        "А": "Значение"
    }
}

obj = B.parse_obj(j)
print(obj.json())

Original Author edited Apr 8 at 16:42 Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

ittutorial team

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment