尝试发送带有希腊文件名的文件时出现UnicodeError [英] UnicodeError when try to send a file with greek filename
问题描述
我已经在set()中创建并填充了希腊名称,然后将这组值传递给视图函数.
I have created and populated Greek names in a set() and I then pass this set of values to a view function.
当我尝试打印此集时,希腊名称显示为乱码.我认为这与Apache mod_wsgi或Bottle不能从utf-8支持开始是有联系的.
When I try to print this set Greek names appear as jibberish. I believe this has somethign to do that Apache mod_wsgi or Bottle doens't start with utf-8 support.
我如何告诉Apache/Bottle使用LANG = el_GR.utf-8,以便我可以正确显示unicode,因为我认为是这种情况?
How can I tell Apache/Bottle to use LANG=el_GR.utf-8 so I can display unicode properly because I believe that's the case here?
我在httpd.conf中查找了AddDefaultCharset utf-8,但该功能已启用,因此我不得不问为什么希腊字符显示为乱码?
I looked for AddDefaultCharset utf-8 in httpd.conf but it is already enabled, so I have to ask why the Greek chars appear as jibberish?
这是我尝试下载具有希腊文文件名的文件的时候.
This is when i try to download a file with a greek filename.
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)
用于下载文件的代码为:
The code use to download the file is:
return static_file(filename, root='/static/files', download=True)
我的系统符合utf-8
my system is et to utf-8
[root@superhost public_html]# echo $LANG
en_US.UTF-8
也许是Apache的东西,还是Python3的探针?
Perhaps something with Apache or is it a probelm with Python3 ?
推荐答案
您不能将Bottle static_file()
与unicode文件名和 download = True
一起使用.请参见此问题的答案针对此限制的两种替代解决方案.
You can't use Bottle static_file()
with unicode filename and download=True
. See accepted answer for this question for two alternative solutions of this limitation.
这篇关于尝试发送带有希腊文件名的文件时出现UnicodeError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!