0

I'm trying to write an html but I have some problems with the characters encoding.

this is my description:

Samsung Galaxy Grand Prime Dual Sim Il Samsung Galaxy Grand Prime è uno smartphone Dual SIM Dual Standby con scocca monoblocco basato sul sistema operativo Android 4.4.2, con supporto alle reti UMTS/GSM e connettività [...]

but when I write it using

self.wfile.write(desc)

I receive this error

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1086: ordinal not in range(128)

The problem is with the à characters.

I need to find I way to encode it and pass to the function

I don't want to use something like

footer=footer.replace("à","a")

I need a general method that can works for all characters and if is possible the method must keep the accent.

Usi Usi
  • 2,967
  • 5
  • 38
  • 69
  • Try UnicodeDammit. Part of beautiful soup. from bs4 import UnicodeDammit –  Aug 30 '15 at 15:37

1 Answers1

0

Have you tried using UTF-8? UTF strings have many of the same properties as an ASCII string.

https://docs.python.org/2/howto/unicode.html

# Assignment
>>> s = u' alle reti UMTS/GSM e connettività'

# As a function parameter
>>> def test(string):
...     print string

>>> test(u'connettività')

connettività
Lev
  • 1,698
  • 3
  • 18
  • 26