【问题标题】:UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 40: character maps to <undefined>UnicodeDecodeError:“charmap”编解码器无法解码位置 40 中的字节 0x81:字符映射到 <undefined>
【发布时间】:2019-09-17 17:02:57
【问题描述】:

我正在尝试加载 mdl 文件,但它给了我错误。这是我的代码:

def load(clf_file):
    with open(clf_file) as fp:
        clf = c.load(fp)
    return clf

clf = load("model.mdl")

运行后它给我这个错误:

UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 40: character maps to <undefined>

clf = load("model.mdl") 线。

我在with open(clf_file,encoding='utf8') as fp: 这一行使用了encoding='utf8',但仍然出现同样的错误。

【问题讨论】:

  • 该文件显然是用不同的编码编码的。尝试latin-1 作为初学者。
  • 还是不行

标签: python-3.x


【解决方案1】:

只需添加“rb”选项来读取二进制代码,它就可以工作了。 索恩-

with open('response_list/flight_res.json', 'rb') as json_file.

希望这会奏效。

【讨论】:

    猜你喜欢
    • 2019-10-20
    • 2017-02-06
    • 2021-05-06
    • 2021-04-11
    • 2020-02-02
    • 1970-01-01
    • 2019-06-01
    • 1970-01-01
    相关资源
    最近更新 更多