Selection error...

A

Abandoned

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)

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
How can i fix this problem ?
I'm sorry my bad english..
 
C

Carsten Haese

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,
 
D

Dennis Lee Bieber

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,) )
And check the adapter documentation with regards to the placeholder
it uses... It may just want a ? instead of %s
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
C

Carsten Haese

And check the adapter documentation with regards to the placeholder
it uses... It may just want a ? instead of %s

The OP uses psycopg2, which unfortunately uses %s parameter notation. But I
agree, it's worth noting that the parameter style may vary between different
DB-API implementations (until the next version of DB-API, when supporting at
least qmark and named parameter styles becomes mandatory, yay!).
 
A

Abandoned

cursor.execute("SELECT id from templinks where url=%s", (URL,) )
Yes i already try this before ask.

URL.decode('latin-1').encode('utf-8') to transcode it into utf-8.
i know this but how do you know the html encoding's a latin-1 ? Html
encoding is to be iso-8859-9 or ascii or cp1254 ... For this reason
URL.decode('latin-1').encode('utf-8') must give me error. I'm trying
now and whet it finished i write the result here.
Thank you very much for your helps.
 
G

Guilherme Polo

2007/10/21 said:
Yes i already try this before ask.

URL.decode('latin-1').encode('utf-8') to transcode it into utf-8.
i know this but how do you know the html encoding's a latin-1 ?

Try using chardet to detect the encoding
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top