Skip to content Skip to sidebar Skip to footer

Mysql In Python: Unicodeencodeerror: 'ascii'

Hello I am trying to store a string value to MySQL, and i use db.escape_string() so not to escape special characters. The string is Lala*=#&%@<>_?!:;-''/()¥¡¿ But whe

Solution 1:

Try http://pypi.python.org/pypi/Unidecode/0.04.1

For example:

from unidecode importunidecodeyour_string='Lala*=#&%@<>_?!:;-\'"/()¥¡¿'
unidecode(your_string)

Please note that I've escaped the character ' from your string in order to avoid the SyntaxError

Solution 2:

Solution 3:

The error says that there are characters here which do not exist in ASCII (they are unicode instead) Try using:

newStr = u'Lala*=#&%@<>_?!:;-'"/()¥¡¿'

It needs to be declared as Unicode, with u'something' instead. This is unlikely to work from most python shells, so make sure your IDE can support unicode, and that the file you are using has a unicode declaration at the top.

Post a Comment for "Mysql In Python: Unicodeencodeerror: 'ascii'"