invalid byte sequence for encoding:utf8 Postgresql

611 views
Skip to first unread message

emanuel...@gmail.com

unread,
Feb 13, 2008, 2:28:38 AM2/13/08
to sqlalchemy
Hello, I had a postgresql database:
CREATE DATABASE panizzolosas
WITH OWNER = postgres
ENCODING = 'UTF8';

and i'm using sqlalchemy 0.4.2p3.
this is my code
self.metadata=MetaData()

engine = create_engine(stringaDATABASE, encoding='utf-8',
echo=False,convert_unicode=True)

self.metadata.bind= engine

try:

table_ditta=Table('tblditta', self.metadata, autoload=True)

mapper(Ditta, table_ditta)

except :

print "Error"


On the database I had some record with the caracter "à" and if I make
some updates I receive the error

ProgrammingError: (ProgrammingError) invalid byte sequence for
encoding "UTF8": 0xe03537
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".
'UPDATE tblditta SET codice=%(codice)s WHERE tblditta.id = %
(tblditta_id)s' {'tblditta_id': 592, 'codice': 'Cibra Publicit
\xe0577'}

\xe0577 is à I suppose..

Any help would be appreciated.
Thanks..
Bye Emyr

Michael Bayer

unread,
Feb 13, 2008, 10:50:27 AM2/13/08
to sqlal...@googlegroups.com

would need to see the code youre using to insert data. Also, set
"assert_unicode=True" on your create_engine() call; that will
illustrate non unicode strings being passed into the dialect. When
using convert_unicode=True at the engine level, *all* strings must be
python unicode strings, i.e. u'somestring'.


emanuel...@gmail.com

unread,
Feb 14, 2008, 3:41:19 AM2/14/08
to sqlalchemy
Solved....my fault....the file i'm reading was latin1... and I was
using the standard open..
now I use:
self.in_file = codecs.open(self.filename, "r", "latin1")
after that it worked fine...
thanks
On 13 Feb, 16:50, Michael Bayer <mike...@zzzcomputing.com> wrote:
Reply all
Reply to author
Forward
0 new messages