YouTube V3 API – Google.Apis.Requests.RequestErrorBackend错误

后端错误[503]后端错误[503]后端错误[503]后端错误[503]

前段时间,也许是几个月,Google上传服务器的上传时间比过去多得多。 那是你看到的错误。 您的代码没有任何问题,除了您可能只是报告错误而不是处理错误。

您很可能正在使用.Upload方法。 我这样说是因为错误503返回“任务被取消”。 使用.UploadAsync方法时出错。 我在上传程序中使用.UploadAsync.ResumeAsync

当您在使用.Upload方法时收到类似错误时,表示服务器太忙,无法在超时期限内处理您的请求。 您的程序应识别此错误并调用.Resume方法以恢复上载。

或者,您可以使用以下语句将超时从默认的100秒增加到更高的值: YouTube.HttpClient.Timeout = TimeSpan.FromMinutes(HTTP_CLIENT_TIMEOUT_MINUTES);

其中YouTube是YouTubeService对象的变量名称。

根据我的经验,增加超时不如处理错误并请求恢复上载那样有效。 例如,如果将超时设置为五分钟,则如果五分钟后未返回响应,则程序仍将失败。 是的,这可能发生。 我通常将超时设置为两分钟,然后在发生错误时恢复上传。 几乎总是,上传将正确恢复。

有时,上传可能会立即再次超时。 出于这个原因,我会计算我的简历并在触发ProgressChanged IUploadProgress.Uploading事件时重置恢复计数器。 我有三个简历重试的限制,并且从未超过该限制。

基于此线程 ,尝试使用某种forms的指数退避或重试来处理此错误。

示例 :此方法实现指数退避策略以恢复失败的上载。

 def resumable_upload(insert_request): response = None error = None retry = 0 while response is None: try: print "Uploading file..." status, response = insert_request.next_chunk() if 'id' in response: print "Video id '%s' was successfully uploaded." % response['id'] else: exit("The upload failed with an unexpected response: %s" % response) except HttpError, e: if e.resp.status in RETRIABLE_STATUS_CODES: error = "A retriable HTTP error %d occurred:\n%s" % (e.resp.status, e.content) else: raise except RETRIABLE_EXCEPTIONS, e: error = "A retriable error occurred: %s" % e if error is not None: print error retry += 1 if retry > MAX_RETRIES: exit("No longer attempting to retry.") max_sleep = 2 ** retry sleep_seconds = random.random() * max_sleep print "Sleeping %f seconds and then retrying..." % sleep_seconds time.sleep(sleep_seconds) 

您还可以使用适用于Google API的可恢复上传协议更可靠地上传video。 此协议允许您在网络中断或其他传输故障后恢复上载操作,从而在网络出现故障时节省时间和带宽。

另请查看以下链接: