Files
pydantic/docs/examples/example2.py
T
Samuel Colvin b10566841e Less verbose errors (#90)
* make errors less verbose, fix #71

* remove track too if null

* update docs

* better dict error, fix #74

* add history
2017-10-23 20:06:48 +01:00

28 lines
542 B
Python

from pydantic import ValidationError
try:
User(signup_ts='broken', friends=[1, 2, 'not number'])
except ValidationError as e:
print(e.json())
"""
{
"friends": [
{
"error_msg": "invalid literal for int() with base 10: 'not number'",
"error_type": "ValueError",
"index": 2,
"track": "int"
}
],
"id": {
"error_msg": "field required",
"error_type": "Missing"
},
"signup_ts": {
"error_msg": "Invalid datetime format",
"error_type": "ValueError",
"track": "datetime"
}
}
"""