Created
March 14, 2022 19:26
-
-
Save pmbrull/cc31a2cfea677bf70a487d09c2df774e to your computer and use it in GitHub Desktop.
How to make the most of Pydantic 03
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pydantic import ValidationError | |
bad_data = { | |
"name": "Lévy", | |
"age": "am I an age?", # Note the type change here | |
"address": { | |
"city": "Wonderland", | |
"zip_code": "ABCDE", | |
"number": 123 | |
} | |
} | |
try: | |
CatRequest.parse_obj(bad_data) | |
except ValidationError as err: | |
print("Something went wrong with the data!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment