TypeError:在psycopg2中的字符串格式化期间,并非所有参数都已转换

时间:2020-03-15 13:34:55

标签: python postgresql pycharm psycopg2

当我使用psycopg2运行以下代码时:

cur.execute(
    """INSERT INTO logmsg (msg_type, file, msg) VALUES %s;""",
    ["Error", str(file), str(sys.exc_info()[0])])

我收到以下错误:

TypeError:在字符串格式化期间并非所有参数都已转换

有人可以帮我吗?

1 个答案:

答案 0 :(得分:1)

VALUES需要用括号括起来的值列表:

cur.execute(
    """INSERT INTO logmsg (msg_type, file, msg) VALUES (%s, %s, %s);""",
    ["Error", str(file), str(sys.exc_info()[0])])

别忘了提交交易。

相关问题