使用Python googleapiclient下载Google Drive文件遇403错误求助
Google Drive API 403错误:标记为恶意/垃圾文件无法下载
近几个月来,我一直使用Python的googleapiclient下载谷歌云端硬盘(Google Drive)中的文件,此前均无异常。但今日尝试下载所有文件时,均出现如下403错误:
HttpError: <HttpError 403 when requesting [API请求地址] returned "This file has been identified as malware or spam and cannot be downloaded.". Details: "[{'domain': 'global', 'reason': 'cannotDownloadAbusiveFile', 'message': 'This file has been identified as malware or spam and cannot be downloaded.'}]">
我已尝试将acknowledgeAbuse参数设置为True,这是此前建议的解决方法,但仍无法解决问题,依然收到相同错误信息,恳请技术支持。以下是我的代码:
from oauth2client.service_account import ServiceAccountCredentials from googleapiclient.discovery import build from google_auth_oauthlib.flow import InstalledAppFlow from google.auth.transport.requests import Request import io from googleapiclient.http import MediaIoBaseDownload scope = ['https://www.googleapis.com/auth/drive'] token = 'C:\Users\tomdr\gsheets_token.json' credentials = ServiceAccountCredentials.from_json_keyfile_name(token, scope) service = build('drive', 'v3', credentials=credentials) #find file_id and filestring to download (won't link code, it's just trivial and not an issue)# request = service.files().get_media(fileId=file_id, acknowledgeAbuse=True) fh = io.FileIO(filestring, 'wb') downloader = MediaIoBaseDownload(fh, request) done = False while done is False: status, done = downloader.next_chunk()
内容的提问来源于stack exchange,提问作者Tom Dry
相关产品推荐
相关产品推荐

