[mod_python] One more UnicodeDecodeError

Flávio Ribeiro listas at flavioribeiro.com
Fri Jun 29 14:34:07 EDT 2007


Here, the full traceback:

Mod_python error: "PythonHandler mod_python.psp"

Traceback (most recent call last):

  File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line
299, in HandlerDispatch
    result = object(req)

  File "/usr/lib/python2.4/site-packages/mod_python/psp.py", line 302,
in handler
    p.run()

  File "/usr/lib/python2.4/site-packages/mod_python/psp.py", line 213, in run
    exec code in global_scope

  File "/home/glossario/cadastro.psp", line 36, in ?
    cadastro = cadastro.cadastra(form['nome'],form['descricao'],fname,form['legenda'],form['fonte'])

  File "/home/glossario/engine.py", line 59, in cadastra
    self.cursor.execute('INSERT BancoDeNomes VALUES (' + self.cadastro + ')')

  File "/usr/lib/python2.4/site-packages/MySQLdb/cursors.py", line
146, in execute
    query = query.encode(charset)

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
31: ordinal not in range(128)



2007/6/27, Martin <gzlist at googlemail.com>:
>
> On 27/06/07, Flávio Ribeiro <listas at flavioribeiro.com> wrote:
> > Hi everyone,
> >
> > Im new to mod_python psp development and im facing my first problem.
> I've
> > already saw some articles on the web but still doesnt fix my code.
> > Im trying to store some data in a mysql database using mysqldb plus
> > mod_python and when i put some text with accents (ã, ç, é, ...) into a
> form
> > input i receive an error:
> >
> > File "/usr/lib/python2.4/site-packages/MySQLdb/cursors.py",
> > line 146, in execute
> >  query = query.encode(charset)
> >
> > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 52:
> > ordinal not in range(128)
>
> You may find a recent thread on a similar topic useful:
> http://www.modpython.org/pipermail/mod_python/2007-June/023904.html
>
> In your particular case it seems (though you have not given the full
> traceback) that you passed a byte string to MySQLdb when it was
> expecting unicode. Therefore it's trying to decode the string using
> the default encoding (ascii) before encoding it again.
>
> You should check the MySQLdb documentation to make sure you are
> calling with the correct parameters, provide the right charset for
> your db if required, and decode any strings you get from forms as
> suggested in the other thread.
>
> Martin
>
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
>



-- 
Flávio Ribeiro
listas at flavioribeiro.com
www.flavioribeiro.com
(83) 9981.4441
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20070629/fbb42785/attachment.html


More information about the Mod_python mailing list