Python 有一个TypeError:execute()在插入mysql表时最多接受3个参数(给定6个)

Python 有一个TypeError:execute()在插入mysql表时最多接受3个参数(给定6个),python,mysql-python,Python,Mysql Python,我已经用python制作了一个webscraper,现在我正试图让它输出我刮到mysqldb中的数据,但是我一直遇到这个错误,我不知道如何修复它。这就是我遇到的错误 File "C:/Users/owner/Downloads/Scrape (2).py", line 16, in <module> cursor.execute("INSERT INTO london10dayforecast (Day,Condition,High,Low,) VALUES (?,?,?,

我已经用python制作了一个webscraper,现在我正试图让它输出我刮到mysqldb中的数据,但是我一直遇到这个错误,我不知道如何修复它。这就是我遇到的错误

 File "C:/Users/owner/Downloads/Scrape (2).py", line 16, in <module>
    cursor.execute("INSERT INTO london10dayforecast (Day,Condition,High,Low,) VALUES (?,?,?,?)", str(var1),str(var2),str(var3),str(var4))
TypeError: execute() takes at most 3 arguments (6 given)

Process finished with exit code 1

您需要将值作为元组传入

cursor.execute("INSERT INTO london10dayforecast (Day,Condition,High,Low) VALUES (%s,%s,%s,%s)", (str(var1),str(var2),str(var3),str(var4)))
或者更容易理解

qstr = "INSERT INTO london10dayforecast (Day,Condition,High,Low) VALUES (%s,%s,%s,%s)"
params = str(var1), str(var2), str(var3), str(var4)
cursor.execute(qstr, params)

这还是问题中的错误吗?如果不是,新的错误是什么?我注意到,即使进行了更正,我仍然得到了这个错误回溯(最近一次调用):文件“C:/Users/owner/Downloads/scrap(2.py)”,第17行,在cursor.execute(qstr,params)文件“C:\Python27\lib\site packages\MySQLdb\cursors.py”,第187行,在execute query=query%tuple([db.literal(item)中)对于参数中的项)TypeError:在字符串转换过程中未转换所有参数formatting@RitchieRamnial,在查询字符串中使用
%s
而不是
在Low旁边有一个额外的逗号。这可能会引起问题。MySQLdb不确定,但我确定它会导致sqlite3出现问题。@RitchieRamnial,仍然是
类型错误:不是所有参数都转换了…
qstr = "INSERT INTO london10dayforecast (Day,Condition,High,Low) VALUES (%s,%s,%s,%s)"
params = str(var1), str(var2), str(var3), str(var4)
cursor.execute(qstr, params)