I am trying to write a program that will connect to our Google apps domain and change the ownership of all files owned by a specific user. I have the code working to some degree but when I try to send a batch http request with all of my insert permission requests, a large percentage of them return with the following.
<HttpError 500 when requesting https://www.googleapis.com/drive/v2/files/0B6zuNvhcekkVNzZ0M3RFdTA1MXc/permissions/18218617888593763709 returned "Internal Error">
It's trivial to write code to retry the failed files but I would like to know why this is happening and if there is anyway I can prevent this behavior, thereby increasing the speed of my program.
Below is my code to change the permissions. I do realize there is a maximum number of requests per batch operation but in our dev environment I'm controlling the number of files that are located on the google drive account, so I'm no where near this number.
def insertNewOwnerPermissions(self, files, new_owner):
"""Insert a new owner into the file
Args:
files: list of files that we want to process
new_owner: new owner's email address
"""
new_permission = {
'value': new_owner,
'type': 'user',
'role': 'owner'
}
#Add all permission requests to batch
for file in files:
self.batch.add(self.driveService.permissions().insert(fileId=str(file['id']), body=new_permission), callback=self.insertCallback, request_id=str(file['id']))
#Send the batch request
self.batch.execute(http=self.http)
def insertCallback(self, request_id, response, exception):
print "id:"+str(request_id)
print "response:"+str(response)
print "exception:"+str(exception)