[mod_python] One more UnicodeDecodeError

Martin gzlist at googlemail.com
Wed Jun 27 16:04:26 EDT 2007

On 27/06/07, Flávio Ribeiro <listas at flavioribeiro.com> wrote:
> Hi everyone,
> Im new to mod_python psp development and im facing my first problem. I've
> already saw some articles on the web but still doesnt fix my code.
> Im trying to store some data in a mysql database using mysqldb plus
> mod_python and when i put some text with accents (ã, ç, é, ...) into a form
> input i receive an error:
> File "/usr/lib/python2.4/site-packages/MySQLdb/cursors.py",
> line 146, in execute
>  query = query.encode(charset)
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 52:
> ordinal not in range(128)

You may find a recent thread on a similar topic useful:

In your particular case it seems (though you have not given the full
traceback) that you passed a byte string to MySQLdb when it was
expecting unicode. Therefore it's trying to decode the string using
the default encoding (ascii) before encoding it again.

You should check the MySQLdb documentation to make sure you are
calling with the correct parameters, provide the right charset for
your db if required, and decode any strings you get from forms as
suggested in the other thread.


More information about the Mod_python mailing list