jinja2 - Python - 'ascii' codec can't decode byte -
i'm using python 2.6 , jinja2 create html reports. provide template many results , template loops through them , creates html tables
when calling template.render, i've started getting error.
<td>{{result.result_str}}</td> unicodedecodeerror: 'ascii' codec can't decode byte 0xc4 in position 0: ordinal not in range(128)
the strange thing is, if set result.result_str simple ascii string "abc" every result, still seeing error. i'm new jinja2 , python , appreciate ideas on how can go investigating problem root cause.
if error string "abc", maybe non-ascii character somewhere else. in template source perhaps?
in case, use unicode strings throughout application avoid kind of problems. if data source provides byte strings, unicode strings byte_string.decode('utf-8')
, if string encoded in utf-8. if source file, use streamreader
class in codecs module.
if you're unsure difference between unicode strings , regular strings, read this: http://www.joelonsoftware.com/articles/unicode.html
Comments
Post a Comment