In database I have saved string in which the problem word is: za\u0161\u010diten.
[ed.: the "problem word" seems to have changed]
When I want to present this string on my page (with req.write(string)). I get this error: UnicodeEncodeError: 'ascii' codec can't encode characters in position 686-687: ordinal not in range(128).
I am using Python 2.X on Windows|linux|Mac. [ed.: select one]
My string is actually named html_h2
. Here are the details I was asked for:
[ed.: whitespace inserted for legibility]
>> print type(html_h2)
<type 'unicode'>
>> print repr(html_h2)
u"\n<table bgcolor='white' border=1 cellpadding=2 cellspacing=1 rules=rows frame=box>
<tr>
<td align='center'>
<img src=img/_up/upload/2010/03/03/… width=120 height=100/>
</td>
<td align='left' style=width:86%>
<h3>V Gr\u010diji kot v vojni</h3>
Gr\u0161ki premier je finan\u010dne razmere v dr\u017eavi, ki je skoraj pred bankrotom, primerjal z razmerami v vojni. Napovedani so ostri var\u010devalni ukrepi.
</td>
</tr>
</table>"
I insert database fields in string with %s. [ed.: irrelevant]
When I do as Ignacio suggested:
req.write(html_h2.encode('XXXXXX'))
where XXXXXX is the charset I declared in the Content-Type header, this happens:
[ed.: delete the outcome that doesn't happen]
(1) It displays just like I'd hoped for.
(2) I get an error message: XXXXXXXXXXXXXXXXXXXXXXXXXX