Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.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
Google Sheets-Python访问超时_Python_Json_Google Sheets Api - Fatal编程技术网

Google Sheets-Python访问超时

Google Sheets-Python访问超时,python,json,google-sheets-api,Python,Json,Google Sheets Api,我正在尝试从谷歌电子表格读写。我在网上找到了这个教程,它似乎对很多人都有用: 到目前为止我所做的: 根据指南创建凭据并下载.json文件 与客户端电子邮件共享立法者电子表格的副本(现在在我的google Drive中) 我在分享后收到一封电子邮件,邮件未送达,因为找不到服务帐户域 我采纳了这个准则 import gspread from oauth2client.service_account import ServiceAccountCredentials scope = ['https

我正在尝试从谷歌电子表格读写。我在网上找到了这个教程,它似乎对很多人都有用:

到目前为止我所做的:

  • 根据指南创建凭据并下载.json文件
  • 与客户端电子邮件共享立法者电子表格的副本(现在在我的google Drive中)

  • 我在分享后收到一封电子邮件,邮件未送达,因为找不到服务帐户域

  • 我采纳了这个准则

    import gspread
    from oauth2client.service_account import ServiceAccountCredentials
    
    scope = ['https://spreadsheets.google.com/feeds']
    creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)
    client = gspread.authorize(creds)
    
    sheet = client.open("Copy of Legislators 2017", scope)
    list_of_hashes = sheet.get_all_records()
    print(list_of_hashes)
    
client_secret.json文件与项目位于同一文件夹中

但是当我运行代码时,我得到以下错误:

日本人说: ”无法连接,因为连接的被叫方即使在一段时间后也没有正确响应。或者连接的主机失败,因为连接的主机没有响应。“

登录似乎有问题,但我不知道如何解决它。 另外,在研究过程中,我发现
范围
部分总是不同的。有人能给我解释一下需要在那里插入什么吗?
有人对此有经验吗?感谢您的帮助:)

确保您的OAuthclientID有效,并且您已经在Google开发控制台中启用了Sheets API

然后,尝试改用Sheetsv4作用域。我记得在使用v3的作用域时遇到了一些错误。希望这能帮助你:

import gspread
from oauth2client.service_account import ServiceAccountCredentials
import pprint

scope = ['https://www.googleapis.com/auth/spreadsheets']
creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)
client = gspread.authorize(creds)

sheet = client.open('NAME_OF_GOOGLE_SHEET').sheet1

pp = pprint.PrettyPrinter()

# get all the records
result = sheet.get_all_records()

pp.pprint(result)      

确保您的OAuthclientID有效,并且您已经在Google开发控制台中启用了Sheets API

然后,尝试改用Sheetsv4作用域。我记得在使用v3的作用域时遇到了一些错误。希望这能帮助你:

import gspread
from oauth2client.service_account import ServiceAccountCredentials
import pprint

scope = ['https://www.googleapis.com/auth/spreadsheets']
creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)
client = gspread.authorize(creds)

sheet = client.open('NAME_OF_GOOGLE_SHEET').sheet1

pp = pprint.PrettyPrinter()

# get all the records
result = sheet.get_all_records()

pp.pprint(result)