Django-使用Apache的生产环境中的UnicodeError
我在生产中遇到一个Django应用程序,它抛出以下错误:Django-使用Apache的生产环境中的UnicodeError,django,apache,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. pGen@rica是上载文件名称的一部分 出现错误的代码如下: files_list = [uuid_t
'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.
pGen@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配置
致以最诚挚的问候,问题已通过以下方式得到纠正:
# 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”更改为“LANG=en_US.UTF-8”,然后重新启动Apache
完成。我假设您是开发人员,机器使用的是python 3?它使用的是python 2.7为什么不在列表左侧使用
os.path.join
?