Tharrry
Tharrry

Reputation: 639

Python gspread update_cell accepts arguments in one function, error in another

Currently working with python and gspread as pratice I ran into a cryptic error.

I have a function to get cell update information:

def update():
    row = get_row()
    col = get_column()
    if (update_validation(row, col)):
        content = get_update_content(col)
        pp.pprint(content)
        really_update(row, col, content)
    else:
        moreinput()

and an extra function to update the cell to reuse later:

def really_update(row, col, content):
    sheet.update_cell(row, col, content)

These two functions work with each other no problem. However, with this function to add columns:

def add_column():
    row = str(0)
    col = str(len(columns)+1)
    print(row)
    print(col)
    add_format()
    name = make_col_name()
    print(name)
    print(type(row), ', ', type(col), ', ',type(name))
    #print(sheet.cell(row,col).value())
    #sheet.update_cell(row, col, name)

As you can see I tried to do some debugging to see if the types matched. They do but still the following error is thrown:

File "test.py", line 184, in main
    add_column()
File "test.py", line 156, in add_column
    print(sheet.cell(row,col).value())
File "C:\Python37\lib\site-packages\gspread\models.py", line 514, in cell
    range_label = '%s!%s' % (self.title, rowcol_to_a1(row, col))
File "C:\Python37\lib\site-packages\gspread\utils.py", line 118, in 
    rowcol_to_a1
raise IncorrectCellLabel('(%s, %s)' % (row, col))
    gspread.exceptions.IncorrectCellLabel: (0, 8)

Any debugging I did did not help solve this, The documentation isn't helpful either.

Any idea what could be wrong? (Hope it's not something like a missing ':' then I'd feel bad) Thanks a lot in advance.

Upvotes: 1

Views: 2856

Answers (1)

Burnash
Burnash

Reputation: 3311

It looks like row in your case is 0:

raise IncorrectCellLabel('(%s, %s)' % (row, col))
    gspread.exceptions.IncorrectCellLabel: (0, 8)

gspread.utils.rowcol_to_a1() which raises the exception, accepts row and column values that start at 1. Documentation is explicit about it:

Parameters:

  • row (int, str) – The row of the cell to be converted. Rows start at index 1.
  • col – The column of the cell to be converted. Columns start at index 1.

Upvotes: 3

Related Questions