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)

查看:362
本文介绍了Python 3 UnicodeDecodeError:'ascii'编解码器无法解码位置0的字节0xe2:序数不在范围内(128)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Windows上实现此笔记本使用Python 3.5.3,并在load_vectors()调用中出现了跟随错误.我尝试过发布不同的解决方案,但没有一个起作用.

I'm implementing this notebook on Windows with Python 3.5.3 and got the follow error on load_vectors() call. 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)

推荐答案

您可能应该提供pickle.load(f, encoding='latin1')的编码,但是请确保文件中的所有字符都将遵循该编码.

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.

默认情况下,您的泡菜代码尝试使用"ASCII"解码文件,但失败.相反,您可以明确指出要使用哪个.请参见文档.

By default, your pickle code is trying to decode the file with 'ASCII' which fails. Instead you can explicitly tell which one to use. See this from Documentation.

如果latin1无法解决问题,请尝试使用encoding='bytes',然后在以后解码所有键和值.

If latin1 doesn't solve, try with encoding='bytes' and then decode all the keys and values later on.

这篇关于Python 3 UnicodeDecodeError:'ascii'编解码器无法解码位置0的字节0xe2:序数不在范围内(128)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆