Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 765
jordan mason Avatar asked Mar 18 '26 06:03

jordan mason


1 Answers

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))
like image 180
DeepSpace Avatar answered Mar 19 '26 19:03

DeepSpace



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!