Selection error...

Carsten Haese carsten at uniqsys.com
Sat Oct 20 22:47:23 EDT 2007


On Sat, 2007-10-20 at 18:28 -0700, Abandoned wrote:
> Hi..
> I want to select datas but some datas give me this error:
> 
> psycopg2.ProgrammingError: invalid byte sequence for encoding "UTF8":
> 0xc720
> HINT:  This error can also happen if the byte sequence does not match
> the encoding expected by the server, which is controlled by
> "client_encoding".
> 
> My select command:
> cursor.execute("SELECT id from templinks where url='%s'"% URL)

Haven't we told you before not to use the % operator to fill values into
a query? Use parameter binding:

cursor.execute("SELECT id from templinks where url=%s", (URL,) )

> This problem occured only select data when i try insert the same data
> it doesn't give me error..
> Note: My database is UTF-8 and the URLS come from different web sites'
> html code

Your string probably contains latin-1 encoded text. Try
URL.decode('latin-1').encode('utf-8') to transcode it into utf-8.

Hope this helps,

-- 
Carsten Haese
http://informixdb.sourceforge.net





More information about the Python-list mailing list