Ginko
Ginko

Reputation: 169

YouTube V3 API - Google.Apis.Requests.RequestErrorBackend Error [503]

I have been uploading videos to YouTube for a while with my software, and everything has been working fine for over a year now. I assume something has changed in the 'backend', and Google tells me to post here with my problems using the tag, so here it is.

This happens when I upload a video. The video uploads to 99%, then this error is thrown. ResumeAsync() seems to constantly throw this error.

C# Side Note: I'm not sure if this holds true for other programming languages, but with the C# API, in order to use ResumeAsync(), you need to set two PRIVATE properties of the ResumableUpload object: UploadUri and StreamLength.

I utilize the UploadAsync and ResumeAsync methods with an 'exponential backoff strategy' implemented as per Google guidelines.

I have tried creating a new developer Client ID, server ID and all that, same result. I have also tried uploading to a different YouTube, same result. It's not a quota issue. My quota is at 5%, besides, I created a new Google developer app.

Google.Apis.YouTube.v3 Runtime: v4.0.30319 Version: 1.12.0.461

Error Google.Apis.Requests.RequestError

Backend Error [503]

Errors [

    Message[Backend Error] Location[ - ] Reason[backendError] Domain[global]

]

System.Net.HttpStatusCode.Gone at Google.Apis.Upload.ResumableUpload`1.d__91.MoveNext() in C:\Users\mdril\Documents\GitHub\google-api-dotnet-client\Src\GoogleApis\Apis[Media]\Upload\ResumableUpload.cs:line 553

EDIT Not too long after these errors appeared, YouTube emailed the following: https://developers.google.com/youtube/terms/required-minimum-functionality

I guess they are preparing for these upcoming requirements. I think soon they are going to write our applications for us! haha! Too much control!

Upvotes: 6

Views: 1472

Answers (2)

abielita
abielita

Reputation: 13494

Based from this thread, try to handle this error at your end with some form of exponential back-off or retry.

Example: This method implements an exponential backoff strategy to resume a failed upload.

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)

You can also upload videos more reliably by using the resumable upload protocol for Google APIs. This protocol lets you resume an upload operation after a network interruption or other transmission failure, saving time and bandwidth in the event of network failures.

Also check these links:

Upvotes: 1

Mike Meinz
Mike Meinz

Reputation: 516

Some time ago, maybe a couple of months, the Google upload servers started timing out on uploads much more than they did in the past. That is the error that you are seeing. There is nothing wrong with your code other than the fact that you are probably just reporting the error rather than handling the error.

Most likely you are using the .Upload method. I say this because an error 503 returns "A task was canceled." error when the .UploadAsync method is used. I use .UploadAsync and .ResumeAsync in my upload program.

When you get an error like this while using the .Upload method, it indicates that the server is too busy to handle your request within the timeout period. Your program should recognize this error and call the .Resume method to resume the upload.

Alternatively, you can increase the timeout from the default 100 seconds to something higher using this statement: YouTube.HttpClient.Timeout = TimeSpan.FromMinutes(HTTP_CLIENT_TIMEOUT_MINUTES);

where YouTube is the variable name of your YouTubeService object.

In my experience, increasing the timeout is not as effective as handling the error and requesting that the upload be resumed. For example, if you set the timeout to five minutes, then your program will still fail if no response is returned after five minutes. Yes, that can happen. I usually set the timeout to two minutes and then resume the upload if an error occurs. Almost always, the upload will resume correctly.

Occasionally, the upload might immediately timeout again. For this reason, I count my resumes and reset the resume counter when a ProgressChanged IUploadProgress.Uploading event is triggered. I have a limit of three resume retries and have never gone over that limit.

Upvotes: 1

Related Questions