首页 > 解决方案 > 如何破译终端在说什么,并可能提供如何让代码工作的解决方案?

问题描述

我对 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.'}

这是我正在使用的教程: 教程

标签: pythonterminal

解决方案


看起来这是一个身份验证问题。您应该验证此用户是否具有打开此文件的正确权限。


推荐阅读