Unicode尝试发送带有希腊语文件名的文件时出错



我在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)

我的系统是 ET 到 UTF-8

[root@superhost public_html]# echo $LANG
en_US.UTF-8

也许是Apache的问题还是Python3的问题?

您不能将瓶子static_file()与 unicode 文件名和download=True一起使用。有关此限制的两种替代解决方案,请参阅此问题的已接受答案。

最新更新