Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 电子表格未找到错误-尝试访问Google工作表_Python_Python 3.x_Google Sheets_Google Sheets Api - Fatal编程技术网

Python 电子表格未找到错误-尝试访问Google工作表

Python 电子表格未找到错误-尝试访问Google工作表,python,python-3.x,google-sheets,google-sheets-api,Python,Python 3.x,Google Sheets,Google Sheets Api,我正在测试这段代码 import gspread from oauth2client.service_account import ServiceAccountCredentials # use creds to create a client to interact with the Google Drive API scope = ['https://www.googleapis.com/auth/spreadsheets', 'https://www.googleapis.com/au

我正在测试这段代码

import gspread
from oauth2client.service_account import ServiceAccountCredentials

# use creds to create a client to interact with the Google Drive API

scope = ['https://www.googleapis.com/auth/spreadsheets', 'https://www.googleapis.com/auth/drive.readonly']

creds = ServiceAccountCredentials.from_json_keyfile_name('C:\\my_path\\client_secret.json', scope)
client = gspread.authorize(creds)

# Find a workbook by name and open the first sheet
# Make sure you use the right name here.
sheet = client.open("Test_Sheet").sheet1

# Extract and print all of the values
list_of_hashes = sheet.get_all_records()
print(list_of_hashes)
我得到这个错误:

SpreadsheetNotFound
我按照下面链接中的说明进行操作


也许我错过了链接的一步,但我不这么认为。也许自从那篇文章发表一年多以来,GCP发生了一些变化。这是可能的,因为云是一个非常动态的地方。解决此类问题的最佳方法是什么?我真的很想让它工作起来,主要是作为一种学习练习,但我也可以看到它在我的工作领域很快会非常有用。谢谢。

好的,我终于明白了。面对这里的植物

在名为“statup_funding.json”的文件中,您必须获取生成的电子邮件,然后单击电子表格上的“共享”按钮,并将该电子邮件地址粘贴到打开的窗口中。然后,一切按预期进行。这是我现在正在工作的代码的最终版本

import gspread
#Service client credential from oauth2client
from oauth2client.service_account import ServiceAccountCredentials
# Print nicely
import pprint
#Create scope
scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
#create some credential using that scope and content of startup_funding.json
creds = ServiceAccountCredentials.from_json_keyfile_name('startup_funding.json',scope)
#create gspread authorize using that credential
client = gspread.authorize(creds)
#Now will can access our google sheets we call client.open on StartupName
sheet = client.open('Test_Sheet').sheet1
pp = pprint.PrettyPrinter()
results = sheet.get_all_records()
results

您是否可以尝试打开列出的电子表格的其他两种方法中的任何一种?也许你的API没有访问该文件的权限。哦,这是一个好问题。我尝试了这三种方法;没有一个奏效。我得到了这个错误:APIRROR:{'code':404,'消息':'未找到请求的实体','状态':'未找到'}。我猜某些凭据或某种权限设置不正确。我要深入调查,看看发生了什么事。我希望错误更具描述性,这样你就可以隔离问题并修复它。在谷歌搜索你的新错误消息时,我在Github上发现了一个可能相关的开放问题。您可以找到它。您是否尝试过使用服务帐户凭据而不是通常的凭据?此外,您是否尝试过访问其他电子表格/表格以确保问题与授权/令牌步骤更相关?