Google Classroom API中的内部错误500

时间:2017-12-17 01:30:08

标签: python google-api google-classroom

当尝试在Python上使用Google API同时执行多项操作时,我会得到一个"内部错误 - 500"什么时候用于某些功能。有时,当我运行相同的代码时,错误会在不同的行上出现。

这是我使用的方法的代码:

batch1 = service.new_batch_http_request(callback=callback)
batch2 = service.new_batch_http_request(callback=callback)
batch3 = service.new_batch_http_request(callback=callback)

batch1.add(service.courses().create(body=arCourse))
batch1.add(service.courses().create(body=ciCourse))
batch1.add(service.courses().create(body=dtCourse))
batch1.add(service.courses().create(body=drCourse))
batch1.add(service.courses().create(body=enCourse))
batch1.execute(http=http)
time.sleep(1)
batch2.add(service.courses().create(body=geCourse))
batch2.add(service.courses().create(body=hiCourse))
batch2.add(service.courses().create(body=icCourse))
batch2.add(service.courses().create(body=laCourse))
batch2.add(service.courses().create(body=maCourse))
batch2.execute(http=http)
time.sleep(1)
batch3.add(service.courses().create(body=muCourse))
batch3.add(service.courses().create(body=peCourse))
batch3.add(service.courses().create(body=reCourse))
batch3.add(service.courses().create(body=scCourse))
batch3.execute(http=http)

我将它分成几批并包括一个“睡眠”。在批次之间,以避免超过Google API上每用户每秒限制的5个查询,但仍然遇到错误。

我在网上发现的类似问题是使用“指数退避”,但我不确定如何在此代码中实现它们。

如果需要,我可以发布更大的代码示例。

1 个答案:

答案 0 :(得分:0)

您可以使用this guide来提高代码的效果。

  

本文档介绍了可用于提高性能的技术   你的申请。您是特定API的文档   使用应该有一个类似的页面,其中一些更详细   主题。

此外,如果您的代码中缺少某些链接,请尝试使用此Python Quickstart guide检查您的代码。

  

完成本页其余部分所述的步骤   五分钟你就会得到一个简单的Python命令行应用程序   向Classroom API发出请求。

相关问题