我正在使用invoice2data库进行发票解析。此库在YAML中有用于解析发票的预定义模板。但是,当我运行示例时,它给出了所有模板的YAML解析错误。
将其运行为:
invoice2data --input-reader tesseract FlipkartInvoice.pdf
例外:
Traceback (most recent call last):
File "/home/webwerks/.local/bin/invoice2data", line 10, in <module>
sys.exit(main())
File "/home/webwerks/.local/lib/python3.5/site-packages/invoice2data/main.py", line 191, in main
templates += read_templates()
File "/home/webwerks/.local/lib/python3.5/site-packages/invoice2data/extract/loader.py", line 88, in read_templates
tpl = ordered_load(template_file.read())
File "/home/webwerks/.local/lib/python3.5/site-packages/invoice2data/extract/loader.py", line 36, in ordered_load
return yaml.load(stream, OrderedLoader)
File "/usr/local/lib/python3.5/dist-packages/yaml/__init__.py", line 112, in load
loader = Loader(stream)
File "/usr/local/lib/python3.5/dist-packages/yaml/loader.py", line 44, in __init__
Reader.__init__(self, stream)
File "/usr/local/lib/python3.5/dist-packages/yaml/reader.py", line 74, in __init__
self.check_printable(stream)
File "/usr/local/lib/python3.5/dist-packages/yaml/reader.py", line 144, in check_printable
'unicode', "special characters are not allowed")
yaml.reader.ReaderError: unacceptable character #x0082: special characters are not allowed
in "<unicode string>", position 312
最后一行说:
File "/usr/local/lib/python3.5/dist-packages/yaml/reader.py", line 144, in check_printable
'unicode', "special characters are not allowed")
yaml.reader.ReaderError: unacceptable character #x0082: special characters are not allowed
in "<unicode string>", position 312
我检查了模板。所有的都是有效的UTF-8格式.
问题似乎是python package.Anyone遇到了这个问题吗?
发布于 2019-04-29 11:45:44
您的输入是否有效,UTF-8与此无关,因为YAML源应该只接受Unicode代码点的子集(独立于UTF-8或其他编码)。
特别是,它只支持Unicode的可打印子集和PyYAML支持的旧YAML 1.1规范,并阐述了这一点:
允许的字符范围显式地排除代理项块#xD 800-#xDFFF、DEL #x7F、C0控制块#x0-#x1F (除#x9、#xA和#xD外)、C1控制块#x80-#x9F、#xFFFE和#xFFFF。任何这样的字符都必须使用转义序列来表示。
因此,不可打印的“允许在这里中断”代码点,0x0082
显然是不允许的(并且不是PyYAML应该允许的事情之一,但不允许)。
https://stackoverflow.com/questions/55902201
复制相似问题