1

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 ?

1 Answers1

1

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.

Alexander Zotov
  • 156
  • 1
  • 5
  • So, i have to omitting the download? And what about the files with Greek filename, how can i give those to the user without Bottle return the error `UnicodeEncodeError('ascii', '/static/files/Î\x92ιÎI saw the link you gave me but didnt understand muhc. How should i write the return? – Νικόλαος Βέργος Sep 24 '18 at 21:33
  • You can try "return static_file(filename, root='/static/files')" with greek filename, this solution worked for the author of original question. Or you can try "return static_file(filename, root='/static/files', download='/some/english/filename')" for sending local greek file with new english filename. – Alexander Zotov Sep 24 '18 at 21:47
  • I does work for me for latin filenames but not for greek ones, which iam receving error ``UnicodeEncodeError('ascii', '/static/files/Î\x92ιÎI ` when i try to download them – Νικόλαος Βέργος Sep 24 '18 at 21:51
  • Then you can try the second variant - "return static_file(filename, root='/static/files', download='some_english_filename')", it should take local file with greek filename and send it to client with english filename. – Alexander Zotov Sep 24 '18 at 22:21
  • it gives me the error `file does nto exists` every time i try to yse `download=....` – Νικόλαος Βέργος Sep 25 '18 at 09:25
  • 1. Add debug printing (before call to `static_file`) of `filename` variable content (along with some greek text) to script output and/or local file to make sure that this variable does contain unicode greek letters and there is no problem with apache. 2. Add debug printing of list of files in /static/files directory to make sure that your file does exist and your script sees local filesystem in greek encoding. P.S.The content of $LANG environment variable can be different for your root shell and for apache process user, so you may have problems with locale for your script. – Alexander Zotov Sep 27 '18 at 11:18