再次出现UnicodeEncodeError(ascii codec无法编码)

Once again, UnicodeEncodeError (ascii codec can't encode)

我是 运行 python 3.6 + gunicorn + django 2.0.5 在 docker 容器中有一些西里尔文项目,这就是我尝试在其中记录西里尔文字符串时看到的使用 Django 控制台。

'ascii' codec can't encode character '\u0410' in position 0: ordinal not in range(128)

这也是 shell

中发生的事情
Python 3.6.5 (default, May  3 2018, 10:08:28) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> :�ириллица

同时,当我运行 python 3.5在docker容器外时,一切正常:

Python 3.5.2 (default, Nov 23 2017, 16:37:01) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> Кириллица

有什么想法可以使 python 3.6 inside docker 与西里尔字符串一起工作吗?

在 python 代码的第一行使用 # -*- coding: utf-8 -*-

并在您的 Dockerfile 中添加:

ENV PYTHONIOENCODING=utf-8