【问题标题】:Numerous Internal Errors (HTPP 500) when trying to BatchHttpRequest to Google Drive API尝试 BatchHttpRequest 到 Google Drive API 时出现许多内部错误 (HTPP 500)
【发布时间】: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


    【解决方案1】:

    这可能是速率限制问题。当您发送批次时,它会到达前端服务器,该服务器将批次解包,然后在 Drive 上触发项目。然后驱动器可以以更新速率呕吐。当我之前遇到此问题时,我得到了 403 速率限制,而不是 500,但众所周知,Drive SDK 错误不一致。

    我最终放弃了批量请求并恢复为单独定时请求。事实证明,这比上传一批然后进行大量重试要有效得多。

    【讨论】:

    • 我考虑过返回个人请求,但我们的用户在其驱动器帐户中拥有数千个文件。恐怕如果我这样做,处理时间会很长。关于如何提高这些操作的效率的任何建议?
    • 为了减少一批请求的耗时,您需要将它们提交到速率限制以下。 Drive 使用令牌/桶系统。根据我的测试,存储桶可容纳大约 30 个令牌,补充速率约为每 2 秒 1 个。确切的数字是一个秘密。一旦你超过这个速度,你就在重试地狱,所以你经过的时间很糟糕。我的测试是 6 个月大,stackoverflow.com/questions/18578768/… 所以事情可能已经改变了。这也是个秘密。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-18
    • 2020-06-08
    • 2012-11-10
    • 2023-03-30
    相关资源
    最近更新 更多