mod_cgi + python 3.2.3 = issue with utf-8 special characters (ñ, é, ç).
lighttpd is quite a handful. It took me forever to realise that the problem was not my code (or python) but lighttpd :(. It is really unworkable guys. The simplest thing like moving lighttpd from port 80 to some other port gave was not doable. I want to adopt this new web server but it is not easy to work with. (tried using it with mono and it give me hell every single step of the way) Now with python this bug I've seen enough.
This issue is easy to reproduce. I have 2 python versions on my linux pc 2.7 en 3.2. The default version on my linux pc 2.7 (/usr/bin/python) and the alternative version at '/usr/bin/python3' For the code I'm using the python 3.2.3 so ofcourse I add in my conf file the following line: 'cgi.assign = ( ".py" => "/usr/bin/python3" )'. So I run the script via lighttpd (1.4.31) and I get the following error: 'UnicodeEncodeError: 'ascii' codec can't encode character '\xf1' in position 36: ordinal not in range(128)'
I run the same script directly on python and I have no errors. I hope this helps you make lighttpd better product.
Updated by darix about 7 years ago
- Status changed from New to Invalid
that error message is from your python interpreter!
not from lighty
# encoding: UTF-8
comment in your file. it might work for your shell because that is set to UTF-8. the locale in which lighty is started is mostlikely "C". so it doesnt know how to interpret that byte.
Updated by adwen about 7 years ago
Ok. I cannot get it to work. Pardon my ignorance on the matter but it seems like something very normal (that I need to set this line in my code). But I've added the '# encoding: UTF-8' line at the top, in the middle, at the bottom of my file. It doesn't change my result. Is it some sort of preprocessor directive? Is there any documentation about this line? sigh....
Also available in: Atom