简体   繁体   中英

During handling of the above exception, another exception occurred: & google sheets not found

import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://www.googleapis.com/auth/drive']
credentials = ServiceAccountCredentials.from_json_keyfile_name('Credentials.json',scope)
result = gspread.authorize(credentials)
res = result.open('A').sheet1
print(res.get_all_records())
Traceback (most recent call last):
  File "C:\Users\Umair\PycharmProjects\Web\venv\lib\site-packages\gspread\client.py", line 123, in open
    self.list_spreadsheet_files()
  File "C:\Users\Umair\PycharmProjects\Web\venv\lib\site-packages\gspread\utils.py", line 37, 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 "C:/Users/Umair/PycharmProjects/Web/PhytonRandom.py", line 6, in <module>
    res = result.open('A').sheet1
  File "C:\Users\Umair\PycharmProjects\Web\venv\lib\site-packages\gspread\client.py", line 131, in open
    raise SpreadsheetNotFound
gspread.exceptions.SpreadsheetNotFound

From the GSpread documentation :

open(title)
Raises: gspread.SpreadsheetNotFound – if no spreadsheet with specified title is found.

The Sheet title specified (in your code, A ) has to exist in your account. Furthermore, the sheet with the name Sheet1 must also be present so it can also be accessed by your line of code res = result.open('A').sheet1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM