码迷,mamicode.com
首页 > 其他好文 > 详细

UnicodeDecodeError: 'ascii' codec can't decode byte错误解决方案

时间:2020-05-04 15:30:24      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:str   方案   not   round   cal   错误信息   sci   utf8   from   

 

异常信息如下:

sh-4.2$ python begin.py
Traceback (most recent call last):
File "/usr/lib64/python2.7/logging/__init__.py", line 874, in emit
stream.write(fs % msg.encode("UTF-8"))
UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0xe5 in position 82: ordinal not in range(128)
Logged from file google.py, line 95
Traceback (most recent call last):
File "/usr/lib64/python2.7/logging/__init__.py", line 874, in emit
stream.write(fs % msg.encode("UTF-8"))
UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0xe5 in position 88: ordinal not in range(128)
Logged from file google.py, line 125
Traceback (most recent call last):
File "/usr/lib64/python2.7/logging/__init__.py", line 874, in emit
stream.write(fs % msg.encode("UTF-8"))
UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0xe5 in position 89: ordinal not in range(128)
Logged from file google.py, line 142
Traceback (most recent call last):
File "/usr/lib64/python2.7/logging/__init__.py", line 874, in emit
stream.write(fs % msg.encode("UTF-8"))
UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0xe5 in position 89: ordinal not in range(128)
Logged from file google.py, line 159

 


本次错误信息出现在logging代码中,python2的解决的办法是,在开头添加如下代码:

import sys
reload(sys)
sys.setdefaultencoding(‘utf8‘)


python3.x下应该改为如下方式:

import importlib
importlib.reload(sys)

UnicodeDecodeError: 'ascii' codec can't decode byte错误解决方案

标签:str   方案   not   round   cal   错误信息   sci   utf8   from   

原文地址:https://www.cnblogs.com/onelikeone/p/12826528.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!