Encoding trouble

Romaric DEFAUX rde at audaxis.com
Wed Dec 15 08:28:07 EST 2010



Le 15/12/2010 14:16, Benedict Verheyen a écrit :
> On 15/12/2010 12:34, Romaric DEFAUX wrote:
> <snip>
>> To create these query, I do this :
>> query = "UPDATE website SET client_name='%s' WHERE ip='%s'" % (self.client_name, self.ip)
>> then self.cursor.execute(query)
>>
> Unicode can be tricky.
> Don't you have to encode the string again?
> I tested this in the interpreter:
>
> a = ("UPDATE website SET client_name='%s'" % "Romariqué Admin").decode("iso-8859-15")
>
> print "Query %s " % a.encode("iso-8859-15")
> produces UPDATE website SET client_name='Romariqué Admin'
>
> So i would try to encode the query before issuing the self.cursor.execute(query)
>
> Cheers,
> Benedict
>
Thanks for your answer :)

I finally found the solution, I removed the following line from my db 
connection :
#               con.cursor().execute('SET NAMES \'utf8\';')
#               con.cursor().execute('SET CHARACTER SET utf8;')
#               con.cursor().execute('SET character_set_connection=utf8;')

And now it's working fine !

Thanks for your help !

Romaric

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5361 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20101215/355bfbd2/attachment-0001.bin>


More information about the Python-list mailing list