【发布时间】:2014-04-24 14:12:51
【问题描述】:
我正在尝试编写一个程序,该程序将连接到我们的 Google Apps 域并更改特定用户拥有的所有文件的所有权。我的代码在某种程度上可以工作,但是当我尝试发送带有所有插入权限请求的批处理 http 请求时,其中很大一部分返回以下内容。
<HttpError 500 when requesting https://www.googleapis.com/drive/v2/files/0B6zuNvhcekkVNzZ0M3RFdTA1MXc/permissions/18218617888593763709 returned "Internal Error">
编写代码重试失败的文件很简单,但我想知道为什么会这样,如果有的话我可以阻止这种行为,从而提高我的程序的速度。
以下是我更改权限的代码。我确实意识到每个批处理操作存在最大请求数,但在我们的开发环境中,我正在控制位于谷歌驱动器帐户上的文件数量,所以我离这个数字很远。
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)
【问题讨论】:
标签: python google-api google-drive-api