Google Classroom API中的内部错误500

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Google Classroom API中的内部错误500相关的知识,希望对你有一定的参考价值。

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

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

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

答案

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

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

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

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

以上是关于Google Classroom API中的内部错误500的主要内容,如果未能解决你的问题,请参考以下文章

Google Classroom API modifyAttachments

Google API - 删除身份验证范围

spring中的class配置不能使用properties中的字符串

对 Google Ads API 的所有请求的内部服务器错误 500

谷歌教室api学生名单

Google API php 快速入门 listFiles() 500 内部错误