簡體   English   中英

使用 gspread 時出現 FileNotFoundError

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM