I am using Google Drive API through pydrive to move files between two google drive accounts. I have been testing with a folder with 16 files. My code always raises an error in the sixth file
"User rate limit exceeded">
I know that there is a limit for the number of request (10/s or 1000/100s), but I have tried the exponential backoff suggested by the Google Drive API to handle this error. Even after 248s it still raises the same error.
Here an example what I am doing
def MoveToFolder(self,files,folder_id,drive):
total_files = len(files)
for cont in range(total_files):
success = False
n=0
while not success:
try:
drive.auth.service.files().copy(fileId=files[cont]['id'],
body={"parents": [{"kind": "drive#fileLink", "id": folder_id}]}).execute()
time.sleep(random.randint(0,1000)/1000)
success = True
except:
wait = (2**n) + (random.randint(0,1000)/1000)
time.sleep(wait)
success = False
n += 1
I tried to use "Batching request" to copy the files, but it raises the same errors for 10 files.
def MoveToFolderBatch(self,files,folder_id,drive):
cont=0
batch = drive.auth.service.new_batch_http_request()
for file in files:
cont+=1
batch.add(drive.auth.service.files().copy(fileId=file['id'],
body={"parents": [
{"kind": "drive#fileLink", "id": folder_id}]}))
batch.execute()
Does anyone have any tips?
EDIT: According to google support:
Regarding your User rate limit exceeded error, is not at all related to the per-user rate limit set in the console. Instead it is coming from internal Google systems that the Drive API relies on and are most likely to occur when a single account owns all the files within a domain. We don't recommend that a single account owns all the files, and instead have individual users in the domain own the files. For transferring files, you can check this link. Also, please check this link on the recommendations to avoid the error.