【发布时间】:2018-09-24 16:46:28
【问题描述】:
我在 set() 中创建并填充了希腊名称,然后将这组值传递给视图函数。
当我尝试打印这组希腊名字时,会出现乱码。我相信这与 Apache mod_wsgi 或 Bottle 不支持 utf-8 开始有关。
我如何告诉 Apache/Bottle 使用 LANG=el_GR.utf-8 以便我可以正确显示 unicode,因为我相信这里就是这种情况?
我在 httpd.conf 中寻找 AddDefaultCharset utf-8 但它已经启用,所以我不得不问为什么希腊字符显示为乱码?
这是当我尝试下载具有希腊文件名的文件时。
Error: 500 Internal Server Error
Sorry, the requested URL 'http://superhost.gr/downloads/file' caused an error:
Internal Server Error
Exception:
UnicodeEncodeError('ascii', '/static/files/Î\x92ιογÏ\x81αÏ\x86ικÏ\x8c - Î\x9dίκοÏ\x82.docx', 14, 34, 'ordinal not in range(128)')
Traceback:
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/bottle.py", line 862, in _handle
return route.call(**args)
File "/usr/lib/python3.6/site-packages/bottle.py", line 1740, in wrapper
rv = callback(*a, **ka)
File "/usr/lib/python3.6/site-packages/bottle.py", line 2690, in wrapper
return func(*a, **ka)
File "/home/nikos/public_html/downloads.py", line 148, in file
return static_file(filename, root='/static/files', download=True)
File "/usr/lib/python3.6/site-packages/bottle.py", line 2471, in static_file
if not os.path.exists(filename) or not os.path.isfile(filename):
File "/usr/lib64/python3.6/genericpath.py", line 19, in exists
os.stat(path)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 14-33: ordinal not in range(128)
用于下载文件的代码是:
return static_file(filename, root='/static/files', download=True)
我的系统是 utf-8 格式
[root@superhost public_html]# echo $LANG
en_US.UTF-8
也许是 Apache 的问题,还是 Python3 的问题?
【问题讨论】: