[英]FileNotFoundError when using gspread
我正在尝试制作一个可以将用户输入添加到谷歌表格中的程序,以便我可以记录它。 到目前为止,我一直一帆风顺。 我正在关注本教程。 现在,当我运行我的代码时,它会输出错误:
FileNotFoundError: [Errno 2] No such file or directory: 'creds.json'
这是我正在运行的代码
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”的文件,我目前将其放在桌面上(这可能是问题所在吗?)
谢谢您的帮助!
如果您使用gspread
并使用服务帐户进行身份验证,则只需按照文档进行操作
function service_account
采用服务帐户 JSON 文件的文件路径,并返回准备好使用的客户端。
像这样:
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.