Hello,
I have a page called addMessage, which adds a message. It is the action of a form with a textarea. In the method, I checked if the user is authorized to add a message, and if not, raised identity.IdentityFailure?. Unfortunately, I got the following error:
500 Internal error
The server encountered an unexpected condition which prevented it from fulfilling the request.
Page handler: 'ordinal not in range(128)'
Traceback (most recent call last):
File "/home/noam/lib/python/CherryPy-2.2.1-py2.4.egg/cherrypy/_cphttptools.py", line 103, in _run
applyFilters('before_main')
File "/home/noam/lib/python/CherryPy-2.2.1-py2.4.egg/cherrypy/filters/__init__.py", line 151, in applyFilters
method()
File "/home/noam/lib/python/CherryPy-2.2.1-py2.4.egg/cherrypy/filters/decodingfilter.py", line 31, in before_main
self.decode(enc)
File "/home/noam/lib/python/CherryPy-2.2.1-py2.4.egg/cherrypy/filters/decodingfilter.py", line 54, in decode
decodedParams[key] = value.decode(enc)
File "encodings/utf_8.py", line 16, in decode
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)
After some fiddling around, it turned out that cherrypy tried to decode a parameter (which was the message text), but it was already decoded. So, I changed cherrypy/filters/decodingfilter.py:54 from
decodedParams[key] = value.decode(enc)
to:
if isinstance(value, unicode):
decodedParams[key] = value
else:
decodedParams[key] = value.decode(enc)
and now it works.
I'm not sure if it's a good fix, or if something more fundamental should be changed.
Have a good day,
Noam