我在脚本中有以下查询:
conn = mysql.connector.connect(**config)
connect = conn.cursor()
params = {'build': self.tc.tag, 'page': self, 'object_id': self.object_id, 'page_header': self.page_header,
'interval': t.interval, 'timestamp': timestamp}
query = u'INSERT INTO page_load_times (build, page, object_id, page_header, elapsed_time, date_run) ' \
'VALUES (%(build)s, %(page)s, %(object_id)s, %(page_header)s, %(interval)s, %(timestamp)s)'
connect.execute(query, params)
conn.commit()
conn.close()
当我运行它时,它会从'page': self
参数中获得以下错误:
"Failed processing pyformat-parameters; %s" % err)
ProgrammingError: Failed processing pyformat-parameters; Python 'appmainmenu'
cannot be converted to a MySQL type
self
仅返回一个unicode字符串。我将'charset': 'utf8', 'use_unicode': True
添加到我的配置中以进行连接,这也没有帮助。
答案 0 :(得分:2)
所以在params词典中我将self
转换为unicode,所以现在它看起来像unicode(self)