python3 运行出现'ascii' codec can't encode characters in position 10-11: ordinal not in range(128)错误解决方案

来源:互联网 发布:sop软件下载 编辑:程序博客网 时间:2024/06/05 17:32

‘ascii’ codec can’t encode characters in position 10-11: ordinal not in range(128)

最近,部署测试环境时新启用了一台Ubuntu,安装完python3执行写好的脚本时报错,差了下基本属于编码问题

可尝试如下解决:

A subtle problem causing even print to fail is having your environment variables set wrong, eg. here LC_ALL set to "C". In Debian they discourage setting it: Debian wiki on Localevim /etc/default/locale#File generated by update-locale#LANG="en_US"LANG="en_US.UTF-8"LANGUAGE="en_US:"$ echo $LANGen_US.utf8$ echo $LC_ALL C$ python -c "print (u'voil\u00e0')"Traceback (most recent call last):  File "<string>", line 1, in <module>UnicodeEncodeError: 'ascii' codec can't encode character u'\xe0' in position 4: ordinal not in range(128)$ export LC_ALL='en_US.utf8'$ python -c "print (u'voil\u00e0')"voilà$ unset LC_ALL$ python -c "print (u'voil\u00e0')"voilà
import sysreload(sys)sys.setdefaultencoding('utf-8')
阅读全文
0 0
原创粉丝点击