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

2024-04-20 15:30:21 发布

您现在位置:Python中文网/ 问答频道 /正文

以下查询似乎无法执行,出现错误- TypeError:不是所有参数都在字符串格式化期间转换。我哪里做错了?你知道吗

    cursor = connection.cursor()

    cursor.execute("INSERT INTO darkweb (onionurl, sitetext) VALUES(%s, 'test') ON CONFLICT (onionurl) DO NOTHING)", (onion))
    connection.commit() 
    cursor.close()

Tags: 字符串testexecute参数on错误connectioncursor
1条回答
网友
1楼 · 发布于 2024-04-20 15:30:21

您需要在输入元组中添加逗号。你知道吗

cursor = connection.cursor()

cursor.execute("INSERT INTO darkweb (onionurl, sitetext) VALUES(%s, 'test') ON CONFLICT (onionurl) DO NOTHING)", (onion,))
connection.commit() 
cursor.close()

或者你可以这样做:

cursor.execute("INSERT INTO darkweb (onionurl, sitetext) VALUES(%s, 'test') ON CONFLICT (onionurl) DO NOTHING)", [onion])

相关问题 更多 >