Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python cerberus-如何验证任意dict密钥?_Python_Cerberus - Fatal编程技术网

Python cerberus-如何验证任意dict密钥?

Python cerberus-如何验证任意dict密钥?,python,cerberus,Python,Cerberus,我读过一些问题,并使用了keysrules和valuesrules,但我只看到它们验证嵌套而不是根。我想验证顶级根目录键的有效性 schema = { 'any_arbitrary_str': { 'type': 'dict', 'keysrules': {'type': 'string'}, 'valuesrules': {'type': 'integer'}, }, } v = Validator(schema) v.vali

我读过一些问题,并使用了keysrules和valuesrules,但我只看到它们验证嵌套而不是根。我想验证顶级根目录键的有效性

schema = {
    'any_arbitrary_str': {
        'type': 'dict',
        'keysrules': {'type': 'string'},
        'valuesrules': {'type': 'integer'},
    },
}

v = Validator(schema)
v.validate({'test': {'a': 1, 'b': 2}})
print(v.errors)
在本例中,我只想验证模式是否为dict of
str:dict[str,int]
,其中键可以是任意字符串


我不确定我是否正确使用了它,这在
cerberus.schema.SchemaError:{'any_arbitral_str':[{'keysrules':['unknown rule'],'valuesrules':['unknown rule']}}
中失败,但它仍然在寻找
any_arbitral_str
而不是任何字符串。

如果要应用于根,嵌套它!-)或者切换到jsonschema。如果要应用于根,请嵌套它!;-)或者切换到jsonschema。