0

I am testing using PyDrive in my web app and the refresh part causes it to return a 500 error. Sometimes it works after awhile but I'm not sure what the conditions are. The same code works locally always. Any idea what could be the issue?

from pydrive.auth import GoogleAuth
gauth = GoogleAuth()
gauth.LoadCredentialsFile("mycreds.txt")
gauth.Refresh()
Anthony M
  • 109
  • 8

1 Answers1

0

Update: Although I can't directly view the errors, it appears trying to refresh authentication tokens on a foreign machine is forbidden. An alternative solution was to go into google cloud and create a service account key for my webapp. I downloaded the key as a json and use that file for authentication. enter image description here enter image description here

Additionally, it seems the service account has its own google drive account that isn't easy to access with my browser (but I could see/control it using pydrive in a terminal). For convenience, I shared a folder using my personal gdrive account to the service accounts email. So now I have the service account save files to that shared folder and it is easy for me to see and control the contents using my personal account

from pydrive.auth import GoogleAuth
gauth = GoogleAuth()

from oauth2client.service_account import ServiceAccountCredentials
scope = ["https://www.googleapis.com/auth/drive"]
gauth.credentials = ServiceAccountCredentials.from_json_keyfile_name('client_secrets_serviceacct.json', scope)

gauth.Authorize()
drive = GoogleDrive(gauth)
file = drive.CreateFile({'title': 'testing.txt', 'parents' : [{'id' : 'mygdrivefolderid'}]})
file.Upload()
Anthony M
  • 109
  • 8