Just got the problem solved !

It is kind of cheating but i works..

here is the code

def dic_lista(lista):
        for i in range(len(lista)):
                for key in lista[i]:
                        try:
                                lista[i][key] = lista[i][key].decode('utf8')
                        except:
                                #lista[i][key] = lista[i][key]
        return lista

when I do a select() in the database, I use the
dic_lista(select_result.as_list())

anyone has a fancier workaround? please tell me !


On Jun 8, 11:43 am, Felipe <felip...@gmail.com> wrote:
> I tried with sqlite, just like you now... and I got
>
> test├®
>
> from de database...
>
> On Jun 8, 11:16 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
>
>
> > I just run this and it works with sqlite. I did not yet have a chance
> > to try it with postgresql.
>
> > # -*- coding: utf-8 -
> > *-
> > db.define_table('test',Field('name'))
> > db.test.insert(name='testé')
> > print db(db.test.id>0).select()
>
> > and it works fine with me. I cannot reproduce your problem which
>
> > On Jun 8, 7:36 am, Felipe <felip...@gmail.com> wrote:
>
> > > xmlrpclib.Fault: <Fault 1: "<type
> > > 'exceptions.UnicodeDecodeError'>:'ascii' codec
> > >  can't decode byte 0xc3 in position 4: ordinal not in range(128)">
>
> > > same problem ...
>
> > > On Jun 7, 3:17 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > > > hmmm, please try
>
> > > > bd[tab].insert(nome=u'testé')
>
> > > > or
>
> > > > bd[tab].insert(nome='testé'.encode('utf8'))
>
> > > > On Jun 7, 9:49 am, Felipe <felip...@gmail.com> wrote:
>
> > > > > Hi,
>
> > > > > I'm having problems with UTF8 words and databases...
>
> > > > > Now I'm using postgres with web2py. I used a xml-rpc script, just for
> > > > > testing, to insert into a table the word 'testé', apparently
> > > > > everything worked well, but when I try to get the info from the table
> > > > > I receive an error, 'cant decode unicode byte ... something', so i
> > > > > went to the postgres comand line and did
>
> > > > > select * from table;
>
> > > > > and i got a testÚ in the table...
>
> > > > > the database is using correct utf8, i know that web2py is also all
> > > > > utf8 and the xml-rpc also used utf8
>
> > > > > here it is come source code
>
> > > > > id = bd[tab].insert(nome='testé')
> > > > >         try:
> > > > >                 bd.commit()
> > > > >                 retorno = 1
> > > > >         except:
> > > > >                 retorno = 0
> > > > >         return retorno

Reply via email to