我目前正在处理Invoice2data库并获得错误。我的模板已经准备好了,但是当我把发票传递给它时,它给了我错误。请帮帮我。
这是我的代码:
import re
from invoice2data import extract_data
from invoice2data.extract.loader import read_templates
templates = read_templates('C:\\Users\\shash\\OneDrive\\Documents\\Desktop\\I\\Templates')
print(templates)
templates_str = re.escape(templates)
result = extract_data('C:\\Users\\shash\\OneDrive\\Documents\\Desktop\\I\\Invoice\\Invoice.pdf',templates)
print("\n")
print(result)以下是我的错误:
Traceback (most recent call last)
Input In [9], in <cell line: 6>()
4 templates = read_templates('C:\\Users\\shash\\OneDrive\\Documents\\Desktop\\I\\Templates')
5 print(templates)
----> 6 templates_str = re.escape(templates)
7 result = extract_data('C:\\Users\\shash\\OneDrive\\Documents\\Desktop\\I\\Invoice\\Invoice.pdf',templates)
8 print("\n")
File D:\Users\shash\anaconda3\lib\re.py:277, in escape(pattern)
275 return pattern.translate(_special_chars_map)
276 else:
--> 277 pattern = str(pattern, 'latin1')
278 return pattern.translate(_special_chars_map).encode('latin1')
TypeError: decoding to str: need a bytes-like object, list found以下是我的模板:
[InvoiceTemplate([('issuer', 'SAVEX TECHNOLOGIES PRIVATE LIMITED'), ('keywords', ['SAVEX TECHNOLOGIES PRIVATE LIMITED', 'WB-10/11, Renaissance logistics park,, Near vil']), ('fields', OrderedDict([('amount', 'TOTAL:\\s+(\\d+,\\d+\\.\\d\\d)'), ('date', 'Invoice Date:\\s+(\\d{1,2}\\.\\d{1,2}\\.\\d{4})'), ('Order_date', 'Order Date:\\s+(\\d{1,2}\\.\\d{1,2}\\.\\d{4})'), ('invoice_number', 'Invoice Number:\\s+(\\w{3}\\d{1,8})')])), ('options', OrderedDict([('remove_whitespace', False), ('currency', 'INR'), ('date_formats', ['%d/%m/%Y']), ('languages', ['en'])])), ('template_name', 'Invoice.yml'), ('exclude_keywords', [])])]发布于 2022-04-10 18:03:06
首先,我试图评论,但我没有50个名誉,所以它不允许我评论。
在我的一个项目中,我面临一个类似的问题,然后我添加了编码到中,这解决了我的问题。
你也可以看看这个,我希望它对你有用。
templates = read_templates('C:\\Users\\shash\\OneDrive\\Documents\\Desktop\\I\\Templates', encodings = 'utf-8')请检查编码和编码。
https://stackoverflow.com/questions/71819085
复制相似问题