Keep getting the error TypeError: function takes at most 2 arguments (3 given)

帅比萌擦擦* 提交于 2019-12-02 21:13:42

问题


I am currently working on my coursework project for college which involves a quiz which stores all background data in a database. With the addition of foreign keys, i have tried to find a way to merge the data from the foreign key between two tables. For example , The users table stores user data and their UserID. The data table will store information about the level of the quiz,etc along with that specific user id. How would that information be automatically updated from the two tables when inserting data?

The method doesnt seem to work, here is some of the code.

difficulty= (1,)
users_id = (1,)  

#values of variables

def users_level(db,cursor,difficulty,users_id):

   cursor.execute("insert into Data (Level,UsersID) VALUES (?,?)",(difficulty),(users_id))

   db.commit()

I am then presented with error:

   cursor.execute("insert into Data (Level,UsersID) VALUES (?,?)",(difficulty),(check_id))
TypeError: function takes at most 2 arguments (3 given)

Is there a solution to this problem? Or potentially an even easier/more efficient method to auto increment id's/data from other tables with foreign keys. Thanks.


回答1:


cursor.execute takes 2 arguments (the query and the query args tuple), yet you are passing it 3 arguments: cursor.execute("insert into Data (Level, UsersID) VALUES (?,?)",(difficulty),(users_id))

You should change (difficulty),(users_id) to a 2-elements tuple, (difficulty, users_id):

cursor.execute("insert into Data (Level, UsersID) VALUES (?,?)", (difficulty, users_id))


来源:https://stackoverflow.com/questions/40465681/keep-getting-the-error-typeerror-function-takes-at-most-2-arguments-3-given

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!