Arpit Rathore
Arpit Rathore

Reputation: 11

It shows me an error when i try to open the google sheet ... Error like StopIteration and gspread.exceptions.SpreadsheetNotFound

import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = ["https://spreadsheets.google.com/feeds",'https://www.googleapis.com/auth/spreadsheets',"https://www.googleapis.com/auth/drive.file","https://www.googleapis.com/auth/drive"]

creds = ServiceAccountCredentials.from_json_keyfile_name("creds.json", scope)

client = gspread.authorize(creds)

sheet = client.open("doc_name").sheet1 # Open the spreadhseet

When i run this code i get the error:

Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/gspread/client.py", line 120, in open properties = finditem( File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/gspread/utils.py", line 88, in finditem return next((item for item in seq if func(item)))

StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Users/samar/PycharmProjects/Automation/sheets.py", line 9, in sheet = client.open("Covid Data 2020-21").sheet1 # Open the spreadhseet File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/gspread/client.py", line 130, in open

raise SpreadsheetNotFound

gspread.exceptions.SpreadsheetNotFound

Upvotes: 1

Views: 1542

Answers (1)

ale13
ale13

Reputation: 6062

The error you are receiving seems to indicate that the spreadsheet with the "doc_name" name you have supplied does not exist.

To retrieve a specific sheet from a specific spreadsheet, I suggest you supply the correct name or make the following change to your code:

spread_sheet = client.open_by_key('SPREADSHEET_ID') 
work_sheet = spread_sheet.worksheet('SHEET_NAME') 

Reference

Upvotes: 0

Related Questions