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