简体   繁体   English

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

[英]Python 3 UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 0: ordinal not in range(128)

I'm implementing this notebook on Windows with Python 3.5.3 and got the follow error on load_vectors() call. 我正在使用Python 3.5.3在Windows上实现这个笔记本 ,并在load_vectors()调用时得到了关注错误。 I've tried different solutions posted but none worked. 我尝试过不同的解决方案,但都没有效果。

<ipython-input-86-dd4c123b0494> in load_vectors(loc)
      1 def load_vectors(loc):
      2     return (load_array(loc+'.dat'),
----> 3         pickle.load(open(loc+'_words.pkl','rb')),
      4         pickle.load(open(loc+'_idx.pkl','rb')))

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

I solved this issue by copying and pasting the entire csv file into text and reading it with: 我通过将整个csv文件复制并粘贴到文本中并使用以下方法读取它来解决此问题:

with open(self.path + "/review_collection.txt", "r", encoding="utf-8") as f:
    read = f.read().splitlines()
    for row in read:
        print(row)

You should probably give encoding for pickle.load(f, encoding='latin1') , but please make sure all the characters in your file will follow the encoding. 您应该为pickle.load(f, encoding='latin1')提供编码,但请确保文件中的所有字符都遵循编码。

By default, your pickle code is trying to decode the file with 'ASCII' which fails. 默认情况下,您的pickle代码正在尝试使用'ASCII'解码文件失败。 Instead you can explicitly tell which one to use. 相反,您可以明确告诉使用哪一个。 See this from Documentation . 文档中查看。

If latin1 doesn't solve, try with encoding='bytes' and then decode all the keys and values later on. 如果latin1没有解决,请尝试使用encoding='bytes'然后解码所有键和值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 UnicodeDecodeError:&#39;ascii&#39; 编解码器无法解码位置 14 中的字节 0xe2:在 GAE python 中序号不在范围内(128)? - UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 14: ordinal not in range(128) in GAE python? Python UnicodeDecodeError:&#39;ascii&#39;编解码器无法解码位置0的字节0xe2:序数不在范围内(128) - Python UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 0: ordinal not in range(128) UnicodeDecodeError:&#39;ascii&#39;编解码器无法解码位置0中的字节0xe2:序号不在范围内(128) - UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 0: ordinal not in range(128) UnicodeDecodeError:“ascii”编解码器无法解码位置 13 中的字节 0xe2:序号不在范围内(128) - UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 13: ordinal not in range(128) 安装熊猫:UnicodeDecodeError:&#39;ascii&#39;编解码器无法解码位置 72 中的字节 0xe2:序号不在范围内(128) - Installing pandas: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 72: ordinal not in range(128) UnicodeDecodeError:&#39;ascii&#39;编解码器无法解码位置139中的字节0xe2:序数不在范围内(128) - UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 139: ordinal not in range(128) UnicodeDecodeError:&#39;ascii&#39;编解码器无法解码位置35的字节0xe2:序数不在范围内(128) - UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 35: ordinal not in range(128) UnicodeDecodeError:&#39;ascii&#39;编解码器无法解码位置4中的字节0xe2:序数不在范围内(128) - UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 4: ordinal not in range(128) Python UnicodeDecodeError:&#39;ascii&#39;编解码器不能解码不在范围内的字节0xe2序数(128) - Python UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 ordinal not in range(128) UnicodeDecodeError:&#39;ascii&#39;编解码器无法解码位置13的字节0xe2:关于读取文件的序数不在range(128)中 - UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 13: ordinal not in range(128), regarding reading in files
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM