python - 如何破译终端在说什么,并可能提供如何让代码工作的解决方案?
问题描述
我对 python 编码以及一般编码都是全新的。我正在做一个从谷歌表格中获取信息并将其显示在终端中的项目。它似乎不起作用,但作为初学者(这是我的第一个项目),我不知道该怎么做。我使用 google api 来获取凭据。这是我写的代码:
import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://spreadsheets.google.com/feeds']
creds = ServiceAccountCredentials.from_json_keyfile_name('sheetsproject-765dzxv233334.json',scope)
client = gspread.authorize(creds)
sheet = client.open('python test').sheet1
options = sheet.get_all_records()
print(options)
这是终端中的结果:
Traceback (most recent call last):
File "/Users/jordanmaggin/Desktop/python/sheets.py", line 9, in <module>
sheet = client.open('python test').sheet1 File "/Users/jordan/opt/anaconda3/lib/python3.7/site-packages/gspread/client.py", line 123, in open
self.list_spreadsheet_files()
File "/Users/jordanmaggin/opt/anaconda3/lib/python3.7/site-packages/gspread/client.py", line 96, in list_spreadsheet_files
res = self.request('get', url, params=params).json()
File "/Users/jordan/opt/anaconda3/lib/python3.7/site-packages/gspread/client.py", line 79, in request
raise APIError(response) gspread.exceptions.APIError: {'errors': [{'domain': 'global', 'reason': 'insufficientPermissions', 'message': 'Insufficient Permission: Request had insufficient authentication scopes.'}], 'code': 403, 'message': 'Insufficient Permission: Request had insufficient authentication scopes.'}
这是我正在使用的教程: 教程
解决方案
看起来这是一个身份验证问题。您应该验证此用户是否具有打开此文件的正确权限。
推荐阅读
- javascript - 为什么动画回调函数不执行?
- machine-learning - 为什么在分类数据集中用 -99999 替换缺失值
- python - 使用字典从 csv 文件创建图形
- python - 如何根据第一次出现从 DataFrame 中检索行
- vim - vim 颜色方案不在 Windows 命令行中呈现
- javascript - TypeError:无法读取未定义 React.js 的属性“用户名”
- http - [HTTP]为什么分号参数不再常用?
- window-functions - 在 Presto 中进行基于范围的交叉连接的最佳方法是什么?
- linux - Linux alsa:更改 alsa 输出中左/右声道的音量
- python - 测试单元素列表以避免 IndexErrors 的 Pythonic 方法