6

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!

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Ginko
  • 149
  • 2
  • 12
  • FWIW, I'm experiencing this as well. Code that worked fine for a year plus all the sudden started failing. I'm also using the C# v3 sdk. – irhetoric Aug 02 '16 at 05:06
  • Thanks for the comment! It's nice to know I'm not going crazy!! :)) – Ginko Aug 03 '16 at 05:18
  • I have yet to test, but Google have responded to the issue I raised here: https://code.google.com/p/gdata-issues/issues/detail?id=8439&thanks=8439&ts=1469419853 – Ginko Aug 10 '16 at 00:46

2 Answers2

1

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.

Mike Meinz
  • 506
  • 3
  • 9
  • Hi, I do use UploadAsync and ResumeAsync, I also already use the timeout feature as you mentioned. I did notice the increase in timeouts a few months ago also, I set my timeouts to 5 and it's been pretty good since. Only 1 video out of maybe 500 exceeded 5 retries. However, I don't think it would be timeout as the videos reach 99% OR they cannot get to 1% before this 503 error is thrown. I never get a 503 mid-upload. – Ginko Jul 26 '16 at 10:12
  • Furthermore, after researching Error 503, Google advises developers NOT to call this function again. "503 backendError Server returned an error. Do not retry this query more than once." I really believe something is wrong in the backend, and I have no idea what it is. Is this happening for anybody else??? – Ginko Jul 26 '16 at 10:12
1

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:

Community
  • 1
  • 1
abielita
  • 13,147
  • 2
  • 17
  • 59
  • I do actually have a exponential backoff strategy implemented for this software. It's been in place for a year with no problems whatsoever. However, this would not explain this error appearing when I open the software on a fresh new day, upload the first video, and boom! Same error appears, video doesn't even get to 1%... Immediate error. I then attempt to re-try using a method similar to the above, same results. There is 100% definately a backend issue here. – Ginko Jul 26 '16 at 10:09
  • I do make use of the UploadAsync and ResumeAsync methods, along with my "exponential backoff strategy" as per Google guidelines. I have done the research, and again, this software has been working well for over a year. Something has just happened 2-3 weeks ago causing these 503's. When reading the google docs, it states that the error 'might' be due to an "exponential backoff strategy". Seems like a generic error to me. – Ginko Jul 26 '16 at 10:15