【问题标题】:UnicodeDecodeError: 'ascii' codec can't decode byte 0xdb in position 0: ordinal not in range(128)UnicodeDecodeError:“ascii”编解码器无法解码位置 0 的字节 0xdb:序数不在范围内(128)
【发布时间】:2018-07-26 23:08:40
【问题描述】:

当时我正在使用pickle.load 加载文件时遇到此错误。

with open("tfidf_vectorizer", mode='r+b') as handle:                            
    tfidf_vectorizer = pickle.load(handle)

UnicodeDecodeError: 'ascii' 编解码器无法在位置解码字节 0xdb 0: 序数不在范围内(128)

【问题讨论】:

  • 请将完整的错误回溯添加到您的问题中。
  • 为什么你的文件tfidf_vectorizer没有扩展名。不应该是tfidf_vectorizer.json 或@KlausD 之类的东西。

标签: python python-3.x


【解决方案1】:

在读取文件时尝试设置编码。

例如:

with open("tfidf_vectorizer", mode='r+b', encoding='utf-8') as handle:                            
    tfidf_vectorizer = pickle.load(handle)

【讨论】:

    猜你喜欢
    • 2011-05-13
    • 2014-02-19
    • 2020-11-06
    • 2014-08-12
    • 2013-09-20
    • 2016-07-05
    • 2015-07-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多