在处理上述异常期间,发生了另一个异常:&google sheets not found

2024-10-02 18:20:09 发布

您现在位置:Python中文网/ 问答频道 /正文

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

Tags: inpywebvenvliblinesiteres
1条回答
网友
1楼 · 发布于 2024-10-02 18:20:09

GSpread documentation开始:

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

指定的工作表标题(在您的代码中,A)必须存在于您的帐户中。此外,名为Sheet1的工作表也必须存在,以便代码行res = result.open('A').sheet1也可以访问该工作表

相关问题 更多 >