首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TypeError:解码到str:需要一个类似字节的对象,列表找到

TypeError:解码到str:需要一个类似字节的对象,列表找到
EN

Stack Overflow用户
提问于 2022-04-10 17:40:29
回答 1查看 1.1K关注 0票数 0

我目前正在处理Invoice2data库并获得错误。我的模板已经准备好了,但是当我把发票传递给它时,它给了我错误。请帮帮我。

这是我的代码:

代码语言:javascript
复制
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)

以下是我的错误:

代码语言:javascript
复制
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

以下是我的模板:

代码语言:javascript
复制
[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', [])])]
EN

回答 1

Stack Overflow用户

发布于 2022-04-10 18:03:06

首先,我试图评论,但我没有50个名誉,所以它不允许我评论。

在我的一个项目中,我面临一个类似的问题,然后我添加了编码到中,这解决了我的问题。

你也可以看看这个,我希望它对你有用。

代码语言:javascript
复制
templates = read_templates('C:\\Users\\shash\\OneDrive\\Documents\\Desktop\\I\\Templates', encodings = 'utf-8')

请检查编码和编码。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71819085

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档