UnicodeError when try to send a file with greek filename

I have created and populated Greek names in a set() and I then pass this set of values to a view function.

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.

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?

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)

my system is et to utf-8

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

Perhaps something with Apache or is it a probelm with Python3 ?

Upvotes: 1

Views: 243

Answers (1)

Alexander Zotov
Alexander Zotov

Reputation: 154

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.

Upvotes: 1

Related Questions