TypeError: not all arguments converted during string formatting in psycopg2

十年热恋 提交于 2021-02-11 14:34:54

问题


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])])

I get the following error:

TypeError: not all arguments converted during string formatting

Can someone help me with this?


回答1:


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])])

Do not forget to commit the transaction.



来源:https://stackoverflow.com/questions/60693476/typeerror-not-all-arguments-converted-during-string-formatting-in-psycopg2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!