Django - Apache生产环境中的UnicodeEncodeError

时间:2016-11-30 15:22:06

标签: django apache

我在生产中出现了一个抛出以下错误的Django应用程序:

'ascii' codec can't encode character u'\xe9' in position 97: ordinal not in range(128)
Unicode error hint
The string that could not be encoded/decoded was: P Gen@rica.

P Gen @ rica是上传文件名称的一部分。

出现错误的代码是:

files_list = [uuid_temp_files + '/' + f for f in os.listdir(uuid_temp_files) if os.path.isfile(os.path.join(uuid_temp_files, f))]

在我的开发机器中,一切正常,我可以在文件名中添加重音文件名。

有关生产环境中此错误原因的任何线索?可能是一些Apache配置?

最诚挚的问候,

1 个答案:

答案 0 :(得分:1)

问题已更正:

# CentOS use /etc/sysconfig/httpd to config environment variables.
#
# By default, the httpd process is started in the C locale; to
# change the locale in which the server runs, the LANG
# variable can be set.
#
# LANG=C
LANG=en_US.UTF-8  # you can change to your locale.

在文件中," / etc / sysconfig / httpd"改变" LANG = C" to" LANG = en_US.UTF-8"然后重启Apache。

完成。