MySQLdb

Skip Montanaro skip at pobox.com
Thu Jan 15 10:08:12 EST 2004


    Lukas> I want add the new record to Mysql database. When I use my script
    Lukas> I got an exception "UnicodeEncodeError: 'ascii' codec can't
    Lukas> encode character u'\xe4' in position 12: ordinal not in
    Lukas> range(128).

Lukas,

You will need to encode your Unicode objects before stuffing the resulting
strings into MySQL.  For example:

    utf8foo = foo.encode("utf-8")
    c.execute("insert into blah blah blah", (..., utf8foo, ...))

instead of 

    c.execute("insert into blah blah blah", (..., foo, ...))

Skip




More information about the Python-list mailing list