【发布时间】:2020-01-17 02:08:38
【问题描述】:
这是需要验证的示例数据。 employee_eligibility 嵌套字典中的键是数字字符串“[0-9]+”。
{
"client_id": 1,
"subdomain": "Acme",
"shifts": [
20047, 20048, 20049
],
"employee_eligibility": {
"1": {
"20047": 1,
"20048": 0,
"20049": 1
},
"2": {
"20047": 1,
"20048": 0,
"20049": 1
},
"3": {
"20047": 1,
"20048": 1,
"20049": 0
}
}
}
我已经编写了以下验证模式:
{
"client_id": {"type": "integer"},
"subdomain": {"type": "string"},
"shifts": {"type": "list", "schema": {"type": "integer"}},
"employee_eligibility": {
"type": "dict",
"keysrules": {"type": "string", "regex": "[0-9]+"},
"schema": {
"type": "dict",
"keysrules": {"type": "string", "regex": "[0-9]+"},
"schema": {"type": "integer"}
}
},
}
当我运行验证时,我收到以下错误:
{'employee_eligibility': ['must be of dict type']}
【问题讨论】:
-
你打错了。
keysules应该是keysrules -
感谢键盘和椅子之间的断开连接 :),已修复拼写错误
{'employee_eligibility': ['must be of dict type']} -
请将正确答案标记为已接受。
标签: python validation cerberus