utf 8 - Python 2.6.6 Encoding Error -


here's get.

programmingerror: must not use 8-bit bytestrings unless use text_factory can interpret 8-bit bytestrings (like text_factory = str). highly recommended instead switch application unicode strings.

here's line of code throwing error.

cursor.execute("select path, filename, size, state, modified, created file path=? , filename=?", (path,filename)) 

i tried other way searching here. , made code like.

cursor.execute("select path, filename, size, state, modified, created file path=? , filename=?", (path.decode('utf-8'),filename.decode('utf-8'))) 

but giving error:

unicodedecodeerror: 'utf8' codec can't decode byte 0xf6 in position 1: invalid start byte 

how solve it?

when decode 8bits string, must use actual encoding, not database encoding.

if using latin1, have (tested on 2.7.3) :

>>> txt = "\xe9\xe8" >>> txt '\xe9\xe8' >>> print txt éè >>> utxt = txt.decode("latin1") >>> utxt u'\xe9\xe8' >>> print utxt éè 

so should write :

cursor.execute("select path, filename, size, state, modified, created file path=? , filename=?",      (path.decode('latin1'),filename.decode('latin1'))) 

replacing latin1 your encoding.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -