在docker 容器中 运行代码 一直报错
UnicodeEncodeError: ‘ascii’ codec can’t encode character ‘\u2013’ in position 65: ordinal not in range(128)
原因:中文无法正常编码
import sys
sys.stdout.encoding
'ANSI_X3.4-1968'
解决办法:变成 utf-8编码 但是按照网上搜到的方法都不太行
参考链接 分析了一些原因
个人认为最好的办法:
将python 升级到3.7以上,apt-get包安装的python,默认装了python3.5,而python3.7会强制使用UTF-8编码!
将python3.6 升级到 3.7 :
apt install python3.7
update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
update-alternatives --config python3
Press <enter> to keep the current choice[*], or type