gpt4 book ai didi

python - "Insufficient Permission: Request had insufficient authentication scopes"即使是最通用的范围

转载 作者:行者123 更新时间:2023-12-04 17:26:05 27 4
gpt4 key购买 nike

我正在尝试从我的谷歌驱动器下载电子表格。我正在关注 this reference并且在许可方面遇到问题。我从 https://www.googleapis.com/auth/drive.file 开始得到了这个

"Insufficient Permission: Request had insufficient authentication scopes."
通读 the permission documentationhttps://www.googleapis.com/auth/drive 阅读以下内容.

Full, permissive scope to access all of a user's files, excluding the Application Data folder.


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

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))

最佳答案

"Insufficient Permission: Request had insufficient authentication scopes."


意味着您当前使用的登录凭据不包含足以使用您当前调用的方法的范围。
虽然看起来您的代码正在使用 https://www.googleapis.com/auth/drive 的范围这足以使用 Files.export。
我怀疑发生的事情是您已经验证了您的用户登录并授予了对可能只读的不同范围的访问权限,然后更改您的代码以包含更高级别的范围并且忘记要求您重新验证您的代码用户,因此您当前正在运行的授权访问将不起作用。
您需要使用这个新范围来验证您的代码。

关于python - "Insufficient Permission: Request had insufficient authentication scopes"即使是最通用的范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63332510/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com