首页 > 解决方案 > 使用莳萝负载时出现 UnicodeDecodeError

问题描述

我正在尝试使用 dill.load 加载模型但得到 UnicodeDecodeError。

BASEDIR = './raw/data/'
modelfile = 'xyz.pkl'
model = dill.load(open('%s%s' % (BASEDIR, modelfile), 'rb'))

错误:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc6 in position 0: ordinal not in range(128)

我尝试encoding='utf-8'根据其他可用答案添加,但随后出现 ValueError:

ValueError: binary mode doesn't take an encoding argument

locale在我的 conda 环境终端中的输出:

LANG=
LC_COLLATE="C"
LC_CTYPE="UTF-8"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=

我正在使用 python 3.7

标签: pythonunicodeerror-handlingpython-3.7dill

解决方案


推荐阅读