我正在尝试调用一个函数来执行查询:
def run(self,query):
try:
self.cursor = self.conn.cursor ()
self.cursor.execute(query)
except MySQLdb.Error, e:
logger.info( "Run function with query: %s Error %d: %s" % (query,e.args[0], e.args[1]))
except:
logger.info( "Errorin Run function with query %s" % (query))
此功能适用于大多数查询。
我正在尝试运行一个查询:
insert into NewBooks (title,WikiLink) values
('Five Point Someone – What not to do at IIT!',
'http://en.wikipedia.org/wiki/Five Point Someone – What not to do at IIT!')
此查询引发异常,输出为Errorin Run function with query %s" % (query)
Traceback 错误:错误:我得到的是 UnicodeEncodeError: 'latin-1' codec can't encode character u'\u2013' in position 120: ordinal not in range(256)
当我在 Mysql 命令行上复制并运行时,它起作用了。有人可以解释一下我可能出了什么问题吗?