HttpError 403 (forbidden) when accessing Google Drive using PyDrive

送分小仙女□ 提交于 2020-01-07 04:35:22

问题


I try to perform some operations on my Google Drive using PyDrive (and service account). This account has the right scope set in admin.google.com and in Dev's Console I've turned on both Drive API and Drive SDK.

Here's the code snippet:

credentials = SignedJwtAssertionCredentials(
        service_account_name, #...@developer.gserviceaccount.com
        key, # from file
        scope, # https://www.googleapis.com/auth/drive
        sub='...' # user
)
gauth = GoogleAuth()
gauth.credentials = credentials
gauth.Authorize()
drive = GoogleDrive(gauth)

file1 = drive.CreateFile({'title': 'Hello.txt'})
file1.Upload()

However, I get the following error: pydrive.files.ApiRequestError: <HttpError 403 when requesting https://www.googleapis.com/drive/v2/files?alt=json returned "Forbidden">

Why, oh why?

PS. Using the credentials provided (with a bit different scope) I can succesfully access spreadsheets (with gspread library).

来源:https://stackoverflow.com/questions/26138528/httperror-403-forbidden-when-accessing-google-drive-using-pydrive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!