I have tried to encode user input using .decode("utf-8") . This works if I try "—".decode("utf-8")
in a python terminal, and returns u'\u2014
. However, when I use title=str(data.getfirst("title")).decode("utf-8")
, and "—" is givin as input into the field "title," i get the error
MOD_PYTHON ERROR
ProcessId: 15713
Interpreter: '104.236.175.124'
ServerName: '104.236.175.124'
DocumentRoot: '/var/www/html'
URI: '/news/process'
Location: None
Directory: '/var/www/html/news/'
Filename: '/var/www/html/news/process'
PathInfo: ''
Phase: 'PythonHandler'
Handler: 'main'
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/mod_python/importer.py", line 1537, in HandlerDispatch
default=default_handler, arg=req, silent=hlist.silent)
File "/usr/lib/python2.7/dist-packages/mod_python/importer.py", line 1229, in _process_target
result = _execute_target(config, req, object, arg)
File "/usr/lib/python2.7/dist-packages/mod_python/importer.py", line 1128, in _execute_target
result = object(arg)
File "/var/www/html/news/main.py", line 260, in handler
title=str(data.getfirst("title")).decode("utf-8")
File "/usr/lib/python2.7/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0x97 in position 0: invalid start byte
MODULE CACHE DETAILS
Accessed: Thu Dec 11 22:53:15 2014
Generation: 5
_mp_383c313d3e7418a670f804c3690ec23d {
FileName: '/var/www/html/news/main.py'
Instance: 4
Generation: 5
Modified: Thu Dec 11 22:41:18 2014
Imported: Thu Dec 11 22:44:39 2014
Children: '/var/www/html/news/watermark.py'
}
_mp_4e16edabf4b38a5ecba6b7d6a0929034 {
FileName: '/var/www/html/news/watermark.py'
Instance: 1
Generation: 1
Modified: Sun Dec 7 22:23:13 2014
Imported: Thu Dec 11 22:29:44 2014
}
My Python version is 2.7, and my mod_python version is 3.5.
Thank you for your time,
Daniel