TurboGears:TypeError: decoding Unicode is not supported
在turbogears的20分钟WIKI里面添加用户的时候
500 Internal error
The server encountered an unexpected condition which prevented it from fulfilling the request.
Page handler: <bound method Users.add of <tutorial.controllers.Users instance at 0xb72aabac>>
Traceback (most recent call last):
File "/usr/lib/python2.4/site-packages/CherryPy-2.2.1-py2.4.egg/cherrypy/_cphttptools.py", line 105, in _run
self.main()
File "/usr/lib/python2.4/site-packages/CherryPy-2.2.1-py2.4.egg/cherrypy/_cphttptools.py", line 254, in main
body = page_handler(*virtual_path, **self.params)
File "<string>", line 3, in add
File "/usr/lib/python2.4/site-packages/TurboGears-1.0b1-py2.4.egg/turbogears/controllers.py", line 326, in expose
output = database.run_with_transaction(
File "<string>", line 5, in run_with_transaction
File "/usr/lib/python2.4/site-packages/TurboGears-1.0b1-py2.4.egg/turbogears/database.py", line 246, in so_rwt
retval = func(*args, **kw)
File "<string>", line 5, in _expose
File "/usr/lib/python2.4/site-packages/TurboGears-1.0b1-py2.4.egg/turbogears/controllers.py", line 343, in <lambda>
mapping, fragment, args, kw)))
File "/usr/lib/python2.4/site-packages/TurboGears-1.0b1-py2.4.egg/turbogears/controllers.py", line 367, in _execute_func
output = errorhandling.try_call(func, *args, **kw)
File "/usr/lib/python2.4/site-packages/TurboGears-1.0b1-py2.4.egg/turbogears/errorhandling.py", line 71, in try_call
return func(self, *args, **kw)
File "/home/hanyh/work/python/tutorial/tutorial/controllers.py", line 50, in add
user = model.User.byEmail(email)
File "<string>", line 1, in <lambda>
File "/usr/lib/python2.4/site-packages/SQLObject-0.7.1-py2.4.egg/sqlobject/main.py", line 1271, in _SO_fetchAlternateID
result, obj = cls._findAlternateID(name, dbName, value, connection)
File "/usr/lib/python2.4/site-packages/SQLObject-0.7.1-py2.4.egg/sqlobject/main.py", line 1267, in _findAlternateID
value), None
File "/usr/lib/python2.4/site-packages/SQLObject-0.7.1-py2.4.egg/sqlobject/dbconnection.py", line 591, in _SO_selectOneAlt
return self.queryOne("SELECT %s FROM %s WHERE %s = %s" %
File "/usr/lib/python2.4/site-packages/SQLObject-0.7.1-py2.4.egg/sqlobject/dbconnection.py", line 761, in queryOne
return self._dbConnection._queryOne(self._connection, s)
File "/usr/lib/python2.4/site-packages/SQLObject-0.7.1-py2.4.egg/sqlobject/dbconnection.py", line 343, in _queryOne
self._executeRetry(conn, c, s)
File "/usr/lib/python2.4/site-packages/SQLObject-0.7.1-py2.4.egg/sqlobject/mysql/mysqlconnection.py", line 73, in _executeRetry
myquery = unicode(query, self.encoding)
TypeError: decoding Unicode is not supported
我把FORM的字段ENCODE了也不行:如下
@expose()
def add(self, email):
# Remove extra spaces
email = email.strip()
# Remove null bytes (they can seriously screw up the database)
email = email.replace('\x00', '')
if email:
try:
user = model.User.byEmail(email)
except model.SQLObjectNotFound:
# email = email.encode('utf-8')
a = unicode( email, "utf-8" )
user = model.User(email=a)
turbogears.flash("User %s added!" % email)
else:
turbogears.flash("User %s already exists!" % email)
else:
turbogears.flash("E-mail must be non-empty!")
raise cherrypy.HTTPRedirect('index')
怎么一回事情?