我在脚本中有以下查询:
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
添加到我的连接配置中,但这也没有帮助。
最佳答案
所以在 params 字典中我将 self
转换为 unicode 所以现在它看起来像 unicode(self)
关于mysql - 处理 pyformat 参数失败; %s"% 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24944078/