Understanding Unicode & encodings

Raphael.Benedet at gmail.com Raphael.Benedet at gmail.com
Sun Jul 23 08:46:17 EDT 2006


Hello,

For my application, I would like to execute an SQL query like this:
self.dbCursor.execute("INSERT INTO track (name, nbr, idartist, idalbum,
path) VALUES ('%s', %s, %s, %s, '%s')" % (track, nbr, idartist,
idalbum, path))
where the different variables are returned by the libtagedit python
bindings as Unicode. Every time I execute this, I get an exception like
this:

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

I tried to encode the different variables in many different encodings
(latin1), but I always get an exception. Where does this ascii codec
error comes from? How can I simply build this query string?

Thanks in advance.
Best Regards,
Raphael




More information about the Python-list mailing list