使用 gspread 时出现 FileNotFoundError
FileNotFoundError when using gspread
我正在尝试制作一个可以将用户输入添加到 google sheet 中的程序,以便我可以对其进行记录。到目前为止,我一直一帆风顺。我正在关注 This 教程。现在,当我 运行 我的代码输出错误时:
FileNotFoundError: [Errno 2] No such file or directory: 'creds.json'
这是我的代码 运行ning
import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = ["https://spreadsheets.google.com/feeds",'https://www.googleapis.com/auth/sprea...',"https://www.googleapis.com/auth/drive...","https://www.googleapis.com/auth/drive"]
creds = ServiceAccountCredentials.from_json_keyfile_name("creds.json", scope)
client = gspread.authorize(creds)
标题为“creds.json”的文件,我目前将其放在桌面上(这可能是问题所在吗?)
Thank-you 求助!
如果您使用 gspread
并使用服务帐户进行身份验证,您只需按照 documentation
函数 service_account
获取服务帐户 JSON 文件和 returns 客户端准备使用的文件路径。
像这样:
gc = gspread.service_account("./my_ceeds.json")
sh = gc.open("Example spreadsheet")
print(sh.sheet1.get('A1'))
我正在尝试制作一个可以将用户输入添加到 google sheet 中的程序,以便我可以对其进行记录。到目前为止,我一直一帆风顺。我正在关注 This 教程。现在,当我 运行 我的代码输出错误时:
FileNotFoundError: [Errno 2] No such file or directory: 'creds.json'
这是我的代码 运行ning
import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = ["https://spreadsheets.google.com/feeds",'https://www.googleapis.com/auth/sprea...',"https://www.googleapis.com/auth/drive...","https://www.googleapis.com/auth/drive"]
creds = ServiceAccountCredentials.from_json_keyfile_name("creds.json", scope)
client = gspread.authorize(creds)
标题为“creds.json”的文件,我目前将其放在桌面上(这可能是问题所在吗?)
Thank-you 求助!
如果您使用 gspread
并使用服务帐户进行身份验证,您只需按照 documentation
函数 service_account
获取服务帐户 JSON 文件和 returns 客户端准备使用的文件路径。
像这样:
gc = gspread.service_account("./my_ceeds.json")
sh = gc.open("Example spreadsheet")
print(sh.sheet1.get('A1'))