以下查询似乎无法执行,并显示以下错误- TypeError:并非在字符串格式化期间转换了所有参数。我在哪里错了?
cursor = connection.cursor()
cursor.execute("INSERT INTO darkweb (onionurl, sitetext) VALUES(%s, 'test') ON CONFLICT (onionurl) DO NOTHING)", (onion))
connection.commit()
cursor.close()
答案 0 :(得分:1)
您需要在输入元组中添加逗号。
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])