我正在尝试编写一个程序,该程序将连接到我们的Google应用程序域并更改特定用户拥有的所有文件的所有权。我的代码在某种程度上工作,但是当我尝试发送带有我所有插入权限请求的批量http请求时,其中很大一部分会返回以下内容。试图向Google云端硬盘API批量发送HttpRequest时出现众多内部错误(HTPP 500)
<HttpError 500 when requesting https://www.googleapis.com/drive/v2/files/0B6zuNvhcekkVNzZ0M3RFdTA1MXc/permissions/18218617888593763709 returned "Internal Error">
是微不足道的编写代码来重试失败的文件,但我想知道为什么发生这种情况,如果有反正我可以阻止这种行为,从而提高了我的程序的速度。
以下是我的代码来更改权限。我知道每批操作的请求数量是最大的,但在我们的开发环境中,我控制的是位于Google云端硬盘帐户上的文件数量,所以我不在这个数字附近。
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)
我想回到个人的要求,但我们有用户在他们的驱动器帐户数以千计的文件。我害怕如果我这样做,处理时间将是离谱的。关于如何提高这些操作效率的任何建议? – LexNix
为了减少一批请求的运行时间,您需要在速率限制以下提交它们。云端硬盘使用令牌/存储桶系统。从我的测试中,水桶容纳大约30个令牌,并且每2秒钟补充率大约为1。确切的数字是一个秘密。一旦你超过这个速度,你就会重试地狱,所以你的经过时间很糟糕。我的测试是6个月,http://stackoverflow.com/questions/18578768/403-rate-limit-on-insert-sometimes-succeeds所以事情可能已经改变。这也是一个秘密。 – pinoyyid