I am having an error with gspread in python

32 views Asked by At

I get an error when trying to use the worksheet.update.

I want it to update cell B2 and C2 but instead it gives this.

 {'code': 400, 'message': 'Requested writing within range [Sheet1!B2:C2], but tried writing to row [3]', 'status': 'INVALID_ARGUMENT'}

this is my code

    if sem == "Sem 1":
        sh.update('B2:C2', [[str(gpa)], [str(unWeightedgpa)]])

It works if the cells used have the same letter. For example if it were A1:A2

1

There are 1 answers

0
Tanaike On

I believe your goal is as follows.

  • You want to put the values of [[str(gpa)], [str(unWeightedgpa)]] to cells "B2:C2" using gspread.

In this case, how about the following modification?

From:

sh.update('B2:C2', [[str(gpa)], [str(unWeightedgpa)]])

To:

sh.update(values=[[str(gpa)], [str(unWeightedgpa)]], range_name='B2')
  • When this script is run with a valid value of sh, the values of [[str(gpa)], [str(unWeightedgpa)]] are put into "B2:C2".

Note:

  • Before you use this script, please confirm the version of your gspread. It seems that the current version is v6.0.2. If your gspread is older, please update it and test it again.

Reference: