J'essaie de télécharger un fichier à partir de Google Drive à l'aide de Python3. Je reçois l'erreur suivante:HttpError 403 lors du téléchargement de fichier à l'aide de l'API Google Drive Python3
Traceback (most recent call last):
File "/run/media/prateek/EC3096E23096B356/Users/Prateek Agrawal/Google Drive/projects/mini-project/cloudDrive/a.py", line 91, in <module>
status, done = downloader.next_chunk()
File "/usr/lib/python3.6/site-packages/oauth2client/_helpers.py", line 133, in positional_wrapper
return wrapped(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/googleapiclient/http.py", line 692, in next_chunk
raise HttpError(resp, content, uri=self._uri)
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/drive/v2/files/0B8C3Gga47u6-MVlPMnR1MENYb2M?alt=media returned "The authenticated user has not granted the app 159208223574 read access to the file 0B8C3Gga47u6-MVlPMnR1MENYb2M">
Mon code est le suivant:
import io
from googleapiclient.http import MediaIoBaseDownload
file_id = '0B8C3Gga47u6-MVlPMnR1MENYb2M'
request = drive_service.files().get_media(fileId=file_id)
fh = io.BytesIO()
downloader = MediaIoBaseDownload(fh, request)
done = False
while done is False:
status, done = downloader.next_chunk()
print("Downloading", status.progress() * 100)
Je trouve ce code sur Google's official tutorial.
Je peux accéder aux métadonnées du fichier mais il est en train de donner une erreur de permission pour télécharger le fichier. Pour l'authentification, j'utilise le même compte Google à partir duquel j'essaie de télécharger ce fichier. J'ai vérifié les métadonnées du fichier et j'ai trouvé dans les métadonnées que j'ai la permission de télécharger (parce que je suis un propriétaire).
Voici les métadonnées du fichier:
{
"kind": "drive#file",
"id": "0B8C3Gga47u6-MVlPMnR1MENYb2M",
"etag": "\"bFBIJPAQTIelBiVAnqXY4FaYwW4/MTUwODI3NjI3NDUzNA\"",
"selfLink": "https://www.googleapis.com/drive/v2/files/0B8C3Gga47u6-MVlPMnR1MENYb2M",
"webContentLink": "https://drive.google.com/uc?id=0B8C3Gga47u6-MVlPMnR1MENYb2M&export=download",
"alternateLink": "https://drive.google.com/file/d/0B8C3Gga47u6-MVlPMnR1MENYb2M/view?usp=drivesdk",
"embedLink": "https://drive.google.com/file/d/0B8C3Gga47u6-MVlPMnR1MENYb2M/preview?usp=drivesdk",
"iconLink": "https://drive-thirdparty.googleusercontent.com/16/type/application/zip",
"title": "folder2-20171017T213157Z-001.zip",
"mimeType": "application/zip",
"labels": {
"starred": false,
"hidden": false,
"trashed": false,
"restricted": false,
"viewed": true
},
"createdDate": "2017-10-17T21:37:54.534Z",
"modifiedDate": "2017-10-17T21:37:54.534Z",
"modifiedByMeDate": "2017-10-17T21:37:54.534Z",
"lastViewedByMeDate": "2017-10-18T09:18:25.901Z",
"markedViewedByMeDate": "1970-01-01T00:00:00.000Z",
"version": "4",
"parents": [
{
"kind": "drive#parentReference",
"id": "0AMC3Gga47u6-Uk9PVA",
"selfLink": "https://www.googleapis.com/drive/v2/files/0B8C3Gga47u6-MVlPMnR1MENYb2M/parents/0AMC3Gga47u6-Uk9PVA",
"parentLink": "https://www.googleapis.com/drive/v2/files/0AMC3Gga47u6-Uk9PVA",
"isRoot": true
}
],
"userPermission": {
"kind": "drive#permission",
"etag": "\"bFBIJPAQTIelBiVAnqXY4FaYwW4/InBwySrqVAcXWoXoJ-e22C6as5M\"",
"id": "me",
"selfLink": "https://www.googleapis.com/drive/v2/files/0B8C3Gga47u6-MVlPMnR1MENYb2M/permissions/me",
"role": "owner",
"type": "user"
},
"originalFilename": "folder2-20171017T213157Z-001.zip",
"fileExtension": "zip",
"md5Checksum": "a97c09989b2c14e3c5866c8390da1daa",
"fileSize": "777",
"quotaBytesUsed": "777",
"ownerNames": [
"Abacus Gla"
],
"owners": [
{
"kind": "drive#user",
"displayName": "Abacus Gla",
"picture": {
"url": "https://lh3.googleusercontent.com/-f5pVFhZGOyo/AAAAAAAAAAI/AAAAAAAAAA0/idMajpfWGVA/s64/photo.jpg"
},
"isAuthenticatedUser": true,
"permissionId": "16118565815584902923",
"emailAddress": "[email protected]"
}
],
"lastModifyingUserName": "Abacus Gla",
"lastModifyingUser": {
"kind": "drive#user",
"displayName": "Abacus Gla",
"picture": {
"url": "https://lh3.googleusercontent.com/-f5pVFhZGOyo/AAAAAAAAAAI/AAAAAAAAAA0/idMajpfWGVA/s64/photo.jpg"
},
"isAuthenticatedUser": true,
"permissionId": "16118565815584902923",
"emailAddress": "[email protected]"
},
"capabilities": {
"canCopy": true,
"canEdit": true
},
"editable": true,
"copyable": true,
"writersCanShare": true,
"shared": false,
"explicitlyTrashed": false,
"appDataContents": false,
"headRevisionId": "0B8C3Gga47u6-WmEvTGx4cms0eGtJOTVaRXZtU2gwN2JoTG1FPQ",
"spaces": [
"drive"
]
Comment puis-je résoudre ce problème? Existe-t-il un moyen alternatif pour télécharger un fichier en utilisant Python3?