Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pydrive.auth.RefreshError: Access token refresh failed: invalid_grant: Token has been expired or revoked

Tags:

python

pydrive

so I was building a project which included me saving some in google drive and this is part of the code I used

gauth = GoogleAuth()
gauth.LoadCredentialsFile("mycreds.txt")
if gauth.credentials is None:
    gauth.LocalWebserverAuth()
elif gauth.access_token_expired:
    gauth.Refresh()
else:
    gauth.Authorize()
gauth.SaveCredentialsFile("mycreds.txt")
drive = GoogleDrive(gauth)

It worked fine for a some days but then I started getting this error

pydrive.auth.RefreshError: Access token refresh failed: invalid_grant: Token has been expired or revoked.

It came from the gauth.Refresh() line so does anyone know why this happened and how to fix it?

like image 921
amrha Avatar asked Dec 05 '25 06:12

amrha


2 Answers

I ran into a similar problem with pydrive2. The issue is caused by a revokation of your GDrive.

Try to delete the credentials.json in your root directory and authenticate once more.

like image 107
Paavo Pohndorff Avatar answered Dec 07 '25 20:12

Paavo Pohndorff


I tried removing settings.yaml and run the code again, it should ask you to "login" to your google account. It worked for me.

like image 42
random stuffs Avatar answered Dec 07 '25 19:12

random stuffs