Google Classroom API中的内部错误500

问题描述 投票:0回答:1

当尝试在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个查询,但仍然遇到错误。

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

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

python google-api google-classroom
1个回答
0
投票

您可以使用this guide来增强代码的性能。

本文档介绍了可用于提高应用程序性能的技术。您正在使用的特定API的文档应该有一个类似的页面,其中包含有关这些主题的更多详细信息。

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

完成本页其余部分中描述的步骤,大约五分钟后,您将拥有一个简单的Python命令行应用程序,该应用程序向Classroom API发出请求。

© www.soinside.com 2019 - 2024. All rights reserved.