The Python Oracle

Python gspread CellNotFound exception error

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 5 Looping

--

Chapters
00:00 Python Gspread Cellnotfound Exception Error
00:35 Accepted Answer Score 2
02:08 Thank you

--

Full question
https://stackoverflow.com/questions/5944...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #ifstatement #exception #googlesheetsapi #gspread

#avk47



ACCEPTED ANSWER

Score 2


  • You want to search the cell on a sheet in Spreadsheet using a text.
  • You want to achieve this using gspread with python.
  • You have already been able to get and put values for Spreadsheet with Sheets API.

If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.

Pattern 1:

When cell = sheet.find('test') is used, when test cannot find in the work sheet, an error of gspread.exceptions.CellNotFound: test occurs. Although I cannot understand about I tried adding an exception, except gspread.exceptions.CellNotFound: but it still does not work., I think that your approach is correct. So can you test the following script?

Sample script:

try:
    cell = sheet.find('test')
    print('Yes')
except gspread.exceptions.CellNotFound:  # or except gspread.CellNotFound:
    print('No')

Pattern 2:

When cells = sheet.findall('test') is used, when test cannot find in the work sheet, an empty array is returned. In this pattern, this is used.

Sample script:

cells = sheet.findall('test')
if len(cells) > 0:  # or if cells != []:
    print('Yes')
else:
    print('No')

Note:

  • If above scripts didn't work, can you post your whole script? By this, I would like to confirm it. Of course, please remove your personal information.

References:

If I misunderstood your question and this was not the direction you want, I apologize.