简体   繁体   中英

Insufficient Permission Error 403 : Google Drive Upload (Python)

I am trying to access Google Drive using the Drive API Version 3 (Python). Listing the files seems to work fine. I get insufficient Permission error when I try to upload a file.

I changed My scope to give full permission to my script

SCOPES = 'https://www.googleapis.com/auth/drive'

Below is the block that I use to create the file

file_metadata = {
    'name': 'Contents.pdf',
    'mimeType': 'application/vnd.google-apps.file'
}
media = MediaFileUpload('Contents.pdf',
                        mimetype='application/vnd.google-apps.file',
                        resumable=True)
file = service.files().create(body=file_metadata,
                                    media_body=media,
                                    fields='id').execute()
print ('File ID: %s' % file.get('id'))

I get this error message:

ResumableUploadError: HttpError 403 "Insufficient Permission"

I am not sure what is wrong here.

I think that your script works fine. From the error you show, I thought the requirement of reauthorize of access token and refresh token. So please try a following flow.

When you authorize using client_secret.json , a credential JSON file is created. At the default Quickstart, it is created in .credentials of your home directory.

For your current situation, please delete your current the credential JSON file which is not client_secret.json , and reauthorize by launching your script. The default file name of Quickstart is drive-python-quickstart.json .

By this, scope of https://www.googleapis.com/auth/drive is reflected to access token and refresh token, and they are used for uploading process. When the error occurs even if this flow is done, please confirm whether Drive API is enabled at API console, again.

If this was not useful for you, I'm sorry.

也许您已经有一个同名文件了?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM