Google Drive SDK - 500:内部服务器错误:大部分时间文件上传成功 [英] Google Drive SDK - 500: Internal Server error: File uploads successfully most of the time

查看:192
本文介绍了Google Drive SDK - 500:内部服务器错误:大部分时间文件上传成功的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试上传文件时,Google Drive REST API有时会返回500:内部服务器错误。这些错误大部分实际上对应于成功的上传。我们会根据Google的建议重试上传,以便稍后查看重复内容。

The Google Drive REST API sometimes returns a 500: Internal Server Error when attempting to upload a file. Most of these errors actually correspond to a successful upload. We retry the upload as per Google's recommendations only to see duplicates later on.

交易这些错误的建议方式是什么?

What is the recommended way of handing these errors?

推荐答案

Google的文档似乎表明这是他们的内部错误,而不是您可以修复的特定错误。他们建议使用指数回退,这基本上是 - 尝试增加间隔的函数。

Google's documentation seems to indicate that this is an internal error of theirs, and not a specific error that you can fix. They suggest using exponential backoff, which is basically re-attempting the function at increasing intervals.

例如,函数失败。等待2秒钟,然后重试。如果失败,请等待4秒钟。然后是8秒,16,32等。更大的差距意味着您给服务提供的时间越来越多。尽管根据您的需要,您可能希望最终限制时间,以便在停止前最多等待10分钟。

For example, the function fails. Wait 2 seconds and try again. If that fails, wait 4 seconds. Then 8 seconds, 16, 32 etc. The bigger gaps mean that you're giving more and more time for the service to right itself. Though depending on your need you may want to cap the time eventually so that it waits a maximum of 10 minutes before stopping.

retrying 软件包的设置非常好。您可以在重试导入重试中使用,然后使用 retry 作为任何应该重新尝试的函数的装饰器。下面是我的一个例子:

The retrying package has a very good set up for this. You can just from retrying import retry and then use retry as a decorator on any function that should be re-attempted. Here's an example of mine:

@retry(wait_exponential_multiplier=1000, wait_exponential_max=60*1000, stop_max_delay=10*60*1000)
def find_file(name, parent=''):
    ...

要使用装饰器,只需在函数声明之前放置 @retry 。您可以使用 retry(),但您可以通过可选参数来调整计时工作方式。我使用 wait_exponential_multiplier 来调整尝试之间等待时间的增加。 wait_exponential_max 是可以在两次尝试之间等待的最长时间。并且 stop_max_delay 是在引发异常之前它将花费重试的时间。所有的值都是毫秒。

To use the decorator you just need to put @retry before the function declaration. You could just use retry() but there are optional parameters you can pass to adjust how the timing works. I use wait_exponential_multiplier to adjust the increase of waiting time between tries. wait_exponential_max is the maximum time it can spend waiting between attempts. And stop_max_delay is the time it will spend retrying before it raises the exception. All their values are in milliseconds.

这篇关于Google Drive SDK - 500:内部服务器错误:大部分时间文件上传成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆