【发布时间】:2017-07-20 02:06:02
【问题描述】:
我一直在尝试将 google sheet 与 django 集成,我正在尝试使用 gspread。我可以使用 python filename.py 查看数据,但是当我运行 python manage.py runserver 时,我不断收到此错误:
IOError: [Errno 2] 没有这样的文件或目录:'key.json'
由于某种原因,它无法识别我的 json 文件,我也尝试使用不带 .json 的“key”,但不走运。我一直在这里谷歌搜索,这里有什么想法吗?下面是我的代码
***************************下面的代码****************** *************
import gspread
import json
from oauth2client.service_account import ServiceAccountCredentials
import os
scope = ['https://spreadsheets.google.com/feeds']
credentials = ServiceAccountCredentials.from_json_keyfile_name('key.json', scope)
gc = gspread.authorize(credentials)
wks = gc.open("RAMP - Master").sheet1
print wks
cell_list = wks.range('A1:B7')
print cell_list
【问题讨论】:
-
尝试将绝对路径放入您的 json 文件而不是相对路径(例如 '~/keys/key.json' 而不是 'key.json')