2016-11-30 78 views
0

我已經在生產中的Django的應用程序,拋出以下錯誤:Django的 - UnicodeEncodeError在生產環境中使用Apache

'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 [email protected] 

P @代哥斯達黎加是一個上傳文件的名稱的一部分。

其中出現的錯誤代碼是這樣的:

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配置?

此致

+0

我假設你的開發機器是使用python 3? – Sayse

+0

它使用Python2.7 –

+1

爲什麼不在列表理解的左邊使用'os.path.join'? –

回答

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」 到 「LANG =的en_US.UTF-8」然後重新啓動Apache。

完成。