UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte 问题
程序员文章站
2024-02-22 11:43:10
...
解决方案:
方案一:
使用notepad++打开文件,将文件转为utf-8的格式
方案二:
python2 中在.py文件中添加:
import sys
import codecs
defaultencoding = 'utf-8'
if sys.getdefaultencoding() != defaultencoding:
reload(sys)
sys.setdefaultencoding(defaultencoding)
在读文件的时候使用:
因为 python2 中没有 with open (file_name, ‘r’, encoding = ‘utf-8’)中的encoding
with codecs.open(file_name, 'r', 'utf-8') as f:
上一篇: Firebug开发者因Firefox开发过快跳槽到Chrome
下一篇: error UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
推荐阅读
-
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
-
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte解决方法
-
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte 问题
-
error UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
-
调试错误:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
-
pickle报UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0xff in position 0:
-
Anaconda中启动Python时的错误:UnicodeDecodeError: 'gbk' codec can't decode byte 0xaf in position 553
-
UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0xcb in position 260: ordinal not in range(128)
-
命令行调用python出现编码错误:UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0x9a in position 140 完美解决!
-
Python2.7更新pip:UnicodeDecodeError: 'ascii' codec can't decode byte 0xb7 in position 7: ordinal not in range(128)