如何在python中识别使用python的“validictory”包验证失败的地方?
"Failed to validate field '_data' list schema"
- 有没有办法找出哪个字段验证失败了?
答案 0 :(得分:0)
使用type作为validictory中的对象,并提及属性字典的键(作为字段名称),可以识别验证失败的字段
答案 1 :(得分:0)
示例强>
import validictory
schema = {"type":"object","properties":{"field1": {"type":"string", "minLength":3},"field2":{"type":"integer"}}}
try:
validictory.validate({'field1':"ab",'field2':123},schema)
except validictory.FieldValidationError as e:
print "field which failed validation:",e.fieldname
验证失败的字段:field1
try:
validictory.validate({'field1':"abcd",'field2':123.7},schema)
except validictory.FieldValidationError as e:
print "field which failed validation:",e.fieldname
验证失败的字段:field2