UnstructuredReader 加载含中文文件名文件报错解决方案
UnstructuredReader 加载含中文文件名文件报错解决方案
使用 UnstructuredReader 加载含中文文件名的文件时,可能会出现以下错误:
The FileType.UNK file type is not supported in partition.
这个错误可能是由于文件名含有中文字符而导致的。可以尝试将文件名转换为英文或使用 url 编码来解决该问题。例如,可以使用 Python 的 urllib.parse.quote() 函数将文件名编码为 URL 编码格式,然后在加载数据时使用编码后的文件名。
例如:
import urllib.parse
filename = '产品型号.html'
encoded_filename = urllib.parse.quote(filename)
model_docs = loader.load_data(file=Path(f'./data/BWK/{encoded_filename}'), split_documents=False)
这样可以避免文件名含中文字符而导致的错误。
示例代码:
# loader
loader = UnstructuredReader()
doc_set = {}
all_docs = []
for model in product_models:
if os.path.exists(f'./data/BWK/{model}.html'):
filename = f'{model}.html'
encoded_filename = urllib.parse.quote(filename)
model_docs = loader.load_data(file=Path(f'./data/BWK/{encoded_filename}'), split_documents=False)
for d in model_docs:
d.extra_info = {'产品型号': model}
doc_set[model] = model_docs
all_docs.extend(model_docs)
原文地址: https://www.cveoy.top/t/topic/lQww 著作权归作者所有。请勿转载和采集!