carsten at uniqsys.com
Sun Oct 21 04:47:23 CEST 2007
On Sat, 2007-10-20 at 18:28 -0700, Abandoned wrote:
> I want to select datas but some datas give me this error:
> psycopg2.ProgrammingError: invalid byte sequence for encoding "UTF8":
> HINT: This error can also happen if the byte sequence does not match
> the encoding expected by the server, which is controlled by
> 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,
More information about the Python-list