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

Posted by 唐传林 on February 14, 2019

运行python程序时出现以下错误:

UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xe5 in position 0: ordinal not in range(128)

解决办法:
摘自: http://stackoverflow.com/questions/21393758/unicodedecodeerror-ascii-codec-cant-decode-byte-0xe5-in-position-0-ordinal

Figured it out.
I put the following at the start of my python file

1
2
3
import sys
reload(sys)
sys.setdefaultencoding("utf-8")

☛兄dei,请我喝杯茶☚
%