解决UnicodeEncodeError: 'ascii' codec can't encode characters in position 617-620: ordinal not in r...

解决UnicodeEncodeError: 'ascii' codec can't encode characters in position 617-620: ordinal not in range(128)

在一个新的Docker环境下运行python代码出现以上问题,验证服务器运行编码:

[root@1c849a0b8xxx hyr]# python3
Python 3.6.8 (default, Nov 16 2020, 16:55:22) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.stdout.encoding
'ANSI_X3.4-1968'

终端输入此命令修改ANSI_X3.4-1968为UTF-8

export LANG="en_US.UTF-8"
[root@1c849a0b8xxx hyr]# python3
Python 3.6.8 (default, Nov 16 2020, 16:55:22) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.stdout.encoding
'UTF-8'

你可能感兴趣的:(解决UnicodeEncodeError: 'ascii' codec can't encode characters in position 617-620: ordinal not in r...)