我的代码如下:
try:
schema = lxml.etree.RelaxNG(file=schema_file)
schema.assertValid(etree)
except lxml.etree.DocumentInvalid as exception:
print(schema.error_log)
print(exception.error_log)
raise exception
它始终引发DocumentInvalid错误:
DocumentInvalid: Document does not comply with schema
在架构错误日志或全局错误日志中没有打印错误。
这仅适用于某些文件,其他文件正确验证,或提供无法验证的原因。 (这是一个非常长的架构,所以我不会在这里引用它。)
我甚至不知道从哪里开始寻找。原因可能是什么?
答案 0 :(得分:1)
这就是您可以收到错误消息的方法
try:
schema = lxml.etree.RelaxNG(file=schema_file)
schema.assertValid(etree)
except lxml.etree.DocumentInvalid as exception:
print(exception.error_log.filter_from_errors()[0])
raise exception