类型错误:并非所有参数都在 psycopg2 中的字符串格式化期间转换 [英] TypeError: not all arguments converted during string formatting in psycopg2
本文介绍了类型错误:并非所有参数都在 psycopg2 中的字符串格式化期间转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用 psycopg2 运行以下代码时:
When I run the below code with psycopg2:
cur.execute(
"""INSERT INTO logmsg (msg_type, file, msg) VALUES %s;""",
["Error", str(file), str(sys.exc_info()[0])])
我收到以下错误:
TypeError: 在字符串格式化期间并非所有参数都被转换
TypeError: not all arguments converted during string formatting
有人可以帮我吗?
推荐答案
VALUES
需要括号括起来的值列表:
VALUES
needs a list of values enclosed in brackets:
cur.execute(
"""INSERT INTO logmsg (msg_type, file, msg) VALUES (%s, %s, %s);""",
["Error", str(file), str(sys.exc_info()[0])])
不要忘记提交事务.
这篇关于类型错误:并非所有参数都在 psycopg2 中的字符串格式化期间转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文