'utf-8'编解码器无法解码位置928中的字节0x93:无效的起始字节

时间:2019-12-07 19:47:32

标签: python utf-8 decode

因此,我尝试在google collab中上载文本文件,但不断收到此错误。任何帮助将不胜感激。

代码如下:

!pip install pronouncing
!pip install markovify

from google.colab import files
import markovify
import pronouncing

uploaded = files.upload()
for fn in uploaded.keys():
  text = uploaded[fn].decode()

for i in range(10):
  print(text_model.make_short_sentence(50))

这是错误:

UnicodeDecodeError                        Traceback (most recent call last)
<ipython-input-33-734c66054f1c> in <module>()
      5 uploaded = files.upload()
      6 for fn in uploaded.keys():
----> 7   text = uploaded[fn].decode()

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x93 in position 928: invalid start byte

1 个答案:

答案 0 :(得分:-1)

当我遇到同样的情况时,我将文件转换为UTF-8来解决它。

如果您使用PyCharm,只需单击格式(右下方)> UTF-8>转换即可。