【问题标题】:"Insufficient Permission: Request had insufficient authentication scopes" even with most gerneral scope“权限不足:请求的身份验证范围不足”即使是最一般的范围
【发布时间】:2020-11-29 14:30:09
【问题描述】:

我正在尝试从我的 Google 云端硬盘下载电子表格。我正在关注this reference 并且遇到了许可问题。我从https://www.googleapis.com/auth/drive.file 开始并得到了这个

"Insufficient Permission: Request had insufficient authentication scopes."

通过the permission documentation阅读以下内容为https://www.googleapis.com/auth/drive

访问所有用户文件的完整许可范围,不包括应用程序数据文件夹。

但即使使用此范围,我仍然收到相同的错误消息。

我的代码是这样的


import io
import pickle
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from googleapiclient.http import MediaIoBaseDownload

file_id = "FILE ID"

# If modifying these scopes, delete the file token.pickle.
SCOPES = ['https://www.googleapis.com/auth/drive']

with open('token.pickle', 'rb') as token:
   creds = pickle.load(token)

service = build('drive', 'v3', credentials=creds)

request = service.files().export_media(fileId=file_id, mimeType='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')

fh = io.BytesIO()
downloader = MediaIoBaseDownload(fh, request)
done = False
while done is False:
   status, done = downloader.next_chunk()
   print("Download %d%%." % int(status.progress() * 100))

【问题讨论】:

  • 删除token.pickle 并重新进行身份验证时会发生什么?

标签: python google-api google-drive-api google-oauth google-api-python-client


【解决方案1】:

“权限不足:请求的身份验证范围不足。”

表示您当前使用的登录凭据不包含足以使用您当前调用的方法的范围。

虽然您的代码似乎正在使用 https://www.googleapis.com/auth/drive 的范围,这足以使用 Files.export。

我怀疑发生的事情是您已经验证了您的用户登录并授予对不同范围的访问权限,可能是只读的,然后更改您的代码以包含更高级别的范围并忘记要求您重新编写代码- 验证您的用户,以便您当前运行的授权访问将不起作用。

您需要使用这个新范围验证您的代码。

【讨论】:

    猜你喜欢
    • 2019-07-06
    • 1970-01-01
    • 2017-08-09
    • 2021-08-07
    • 2021-01-04
    • 1970-01-01
    • 2021-10-20
    • 2021-10-16
    • 1970-01-01
    相关资源
    最近更新 更多