[英]FileNotFoundError when using gspread
I am trying to make a program that can add user inputs into a google sheet so I can document it.我正在尝试制作一个可以将用户输入添加到谷歌表格中的程序,以便我可以记录它。 I have had smooth sailing up until now.到目前为止,我一直一帆风顺。 I am following This tutorial.我正在关注本教程。 Now when I run my code it outputs the error:现在,当我运行我的代码时,它会输出错误:
FileNotFoundError: [Errno 2] No such file or directory: 'creds.json'
Here is the code I am running这是我正在运行的代码
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)
The file it titled "creds.json" and I currently have it sitting on my desktop (Could this be the issue?)标题为“creds.json”的文件,我目前将其放在桌面上(这可能是问题所在吗?)
Thank-you for your help!谢谢您的帮助!
If you use gspread
and authenticate with a service account you can simply follow the documentation如果您使用gspread
并使用服务帐户进行身份验证,则只需按照文档进行操作
The function service_account
takes the file path of the service account JSON file and returns the client ready to use. function service_account
采用服务帐户 JSON 文件的文件路径,并返回准备好使用的客户端。
Like so:像这样:
gc = gspread.service_account("./my_ceeds.json")
sh = gc.open("Example spreadsheet")
print(sh.sheet1.get('A1'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.