我正在尝试使用gspread读取Google Sheets API的凭据。我编写了以下代码:
class Command(BaseCommand):
def __init__(self,*args,**kwargs):
super().__init__(*args,**kwargs)
def handle(self,**kwargs):
scope = ['https://spreadsheets.google.com/feeds','https://www.googleapis.com/auth/drive']
credentials = ServiceaccountCredentials.from_json_keyfile_name('/static/json/spreadsheets.json',scope)
gc = gspread.authorize(credentials)
wks = gc.open("Where is the money Lebowski?").sheet1
self.stdout.write(self.style.SUCCESS('Succesfully ran "sheets" command'))
读取文件将返回以下错误:
FileNotFoundError: [Errno 2] No such file or directory: 'static/json/spreadsheets.json'
我尝试了多种路径,例如:
- '〜/ static / json / spreadsheets.json'
- '/ json / spreadsheets.json'
- 'spreadsheets.json'
但是似乎没有一个起作用。有人可以帮我吗?