【问题标题】:Internal Error 500 in Google Classroom APIGoogle Classroom API 中的内部错误 500
【发布时间】:2017-12-17 01:30:07
【问题描述】:

当尝试在 Python 中的 Google API 上同时执行多项操作时,对于某些函数,我会收到“内部错误 - 500”。有时,当我运行 same 代码时,错误会出现在不同的行上。

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

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 次查询的限制,但我仍然遇到错误。

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

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

【问题讨论】:

  • 假设每个请求都将单独失败,并对失败的请求实施指数退避。有时,由于某些问题,Google 只会返回 500,请重试您的请求。

标签: python google-api google-classroom


【解决方案1】:

您可以使用this guide 来提高代码的性能。

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-11
    • 2022-11-10
    • 1970-01-01
    相关资源
    最近更新 更多