解决UnicodeEncodeError: 'ascii' codec can't encode characters in position 6-16: ordinal not in range(128)问题

时间:2018-02-02 13:11:07   收藏:0   阅读:2336

在开头加上 
import sys 
reload(sys) 
sys.setdefaultencoding( “utf-8” )

Python自然调用ascii编码解码程序去处理字符流,当字符流不属于ascii范围内,就会抛出异常(ordinal not in range(128))。所以解决方法就是修改默认编码,需要注意的是需要先调用reload方法。

 

有时Jenkins执行会报错,而Python执行时不报错,也是在开头加上 
import sys 
reload(sys) 
sys.setdefaultencoding( “utf-8” )

原文:https://www.cnblogs.com/farmhand/p/8404338.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!