#222 SQLObject 0.9: Unicode interaction problems with MySQLDb

MySQL (29)

E-mail: elvis.pfutzenreuter@gmail.com

After upgrading to TurboGears, SQLObject 0.9 and MySQLdb 1.2.2 final, the Unicode problem still remains.

Changing line 32 of sqlobject/mysql/mysqlconnection.py, from

need_unicode = True


need_unicode = False

solves the problem, as it used to solve in older versions of TurboGears/SQLObject. Maybe it is a bug of MySQLdb, but the code I patched already seems to be a workaround :)

Traceback (most recent call last):
File "/usr/lib/python2.5/site-packages/CherryPy-2.2.1-py2.5.egg/cherrypy/_cphttptools.py", line 105, in _run
File "/usr/lib/python2.5/site-packages/CherryPy-2.2.1-py2.5.egg/cherrypy/_cphttptools.py", line 254, in main
body = page_handler(*virtual_path, **self.params)
File "<string>", line 3, in fetch
File "/usr/lib/python2.5/site-packages/TurboGears-", line 336, in expose
*args, **kw)
File "<string>", line 5, in run_with_transaction
File "/usr/lib/python2.5/site-packages/TurboGears-", line 303, in so_rwt
retval = func(*args, **kw)
File "<string>", line 5, in _expose
File "/usr/lib/python2.5/site-packages/TurboGears-", line 351, in <lambda>
mapping, fragment, args, kw)))
File "/usr/lib/python2.5/site-packages/TurboGears-", line 378, in _execute_func
output = errorhandling.try_call(func, *args, **kw)
File "/usr/lib/python2.5/site-packages/TurboGears-", line 73, in try_call
return func(self, *args, **kw)
File "<string>", line 3, in fetch
File "/usr/lib/python2.5/site-packages/TurboGears-", line 173, in validate
return errorhandling.run_with_errors(errors, func, *args, **kw)
File "/usr/lib/python2.5/site-packages/TurboGears-", line 113, in run_with_errors
return func(self, *args, **kw)
File "/home/epx/luca/luca/sys_users.py", line 191, in fetch
return self.base_fetch(id)
File "/home/epx/luca/luca/simple_table.py", line 395, in base_fetch
File "/home/epx/luca/luca/mylib.py", line 69, in done
File "/home/epx/luca/luca/mylib.py", line 38, in _write
user=current.user, err=self.logerr)
File "/usr/lib/python2.5/site-packages/SQLObject-0.9.0-py2.5.egg/sqlobject/declarative.py", line 94, in _wrapper
return fn(self, *args, **kwargs)
File "/usr/lib/python2.5/site-packages/SQLObject-0.9.0-py2.5.egg/sqlobject/main.py", line 1214, in __init__
self._create(id, **kw)
File "/usr/lib/python2.5/site-packages/SQLObject-0.9.0-py2.5.egg/sqlobject/main.py", line 1245, in _create
File "/usr/lib/python2.5/site-packages/SQLObject-0.9.0-py2.5.egg/sqlobject/main.py", line 1269, in _SO_finishCreate
id, names, values)
File "/usr/lib/python2.5/site-packages/SQLObject-0.9.0-py2.5.egg/sqlobject/dbconnection.py", line 849, in queryInsertID
self._connection, soInstance, id, names, values)
File "/usr/lib/python2.5/site-packages/SQLObject-0.9.0-py2.5.egg/sqlobject/mysql/mysqlconnection.py", line 156, in _queryInsertID
self._executeRetry(conn, c, q)
File "/usr/lib/python2.5/site-packages/SQLObject-0.9.0-py2.5.egg/sqlobject/mysql/mysqlconnection.py", line 113, in _executeRetry
query = unicode(query, self.encoding)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 90: ordinal not in range(128)


  • Oleg Broytman

    Oleg Broytman - 2007-07-20

    Logged In: YES
    Originator: NO

    Does "charset=latin1" or "charset=utf-8" in your DB URI help?

  • Oleg Broytman

    Oleg Broytman - 2007-08-13
    • status: open --> closed

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks