问题
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