I am trying to show email within a webpage. The program is written in Python. Unfortunately, I have some character encoding issues. I have quotes and double quotes in the text.
Original mail:
“All is good”
‘it is getting better’
with character set 'windows-1252' I get from the ISP:
=93All is good=94
=91it is getting better=92
with character set 'utf-8' I get from the ISP:
=E2=80=9CAll is good=E2=80=9D
=E2=80=98it is getting better=E2=80=99
I replace the =..
with their corresponding hex characters. The text then looks like:
character set 'windows-1252'
ôAll is goodö
æit is getting betterÆ
character set 'utf-8'
ΓÇ£All is goodΓÇ¥
ΓÇÿit is getting betterΓÇÖ
Subsequent calls to the unicode function fail with
UnicodeEncodeError: 'charmap' codec can't encode character u'\u201d' in position 6:
character maps to <undefined>
or similar.
The call looks like unicode( message, 'utf-8', 'replace' )
.
Any idea what I am doing wrong?
Why are you replacing anything with anything?
Because did I try this and I ran into problems. Here is another try:
The output looks like:
The output looks like:
You see, fails if I use
decode='true'
. Here is the simplified email: