0

I have a bit of python code using PyDrive, to download files from a shared google drive folder. It looks like this.

from pydrive2.auth import GoogleAuth
from pydrive2.drive import GoogleDrive

gauth = GoogleAuth()
gauth.CommandLineAuth()

drive = GoogleDrive(gauth)

file_list = drive.ListFile({'q': "'XXXXXXXXXXXXXXXXXXXXXXXX' in parents and trashed=false"}).GetList()
for file2 in file_list:
    string = "'"+ file2['id'] +"'" + " in parents and trashed=false"
    file_list2 = drive.ListFile({'q': string}).GetList()
    print(file2['title'], file2['id'])
    for file3 in file_list2:
        file3.GetContentFile('/data/' + file3['title'])
        print('downloaded: ', file3['title'], file3['id'])

This downloads roughly a TB of data in many tens of thousands of files. (The original file link is not XXXXXXXX, I just added that to avoid using the actual file ID in this example). The code works great for like the first 25k files, when it suddenly fails with

code: 403, message: Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.

I sign in successfully with OAuth and my google drive api is enabled and it has a quota of 10,000,000 requests a day (far more than I am using). Why does it think I am still using an anonymous account and hitting me with this error? It is my understanding that because it is a file that I have in my shared drive and because I am signed in I shouldn't be encountering this, whats up with that?

  • 1
    does it fail after an hour by any chance? That error normally means that the Drive API request you have submitted is missing an Authorization header – pinoyyid Nov 11 '20 at 03:33
  • The first time I used it, it ran for like 8 hours and downloaded like 25k files, the second time it ran for like 4 and downloaded like 12k, now it refuses to run and download even a single file despite it being more than 24 hours since the last downloaded file and quota should have reset. That being said it could be the Authorization header, is there an easy way to check that/implement it with PyDrive? – Patrick Jordan Nov 11 '20 at 07:10

0 Answers0