Browse Source

more detailed http error

Arnau Sanchez 9 years ago
parent
commit
4b13608c1b
2 changed files with 11 additions and 4 deletions
  1. 10 2
      youtube_upload/main.py
  2. 1 2
      youtube_upload/upload_video.py

+ 10 - 2
youtube_upload/main.py

@@ -20,6 +20,7 @@ import sys
 import optparse
 import collections
 
+import apiclient.errors
 import oauth2client
 
 import youtube_upload.auth
@@ -36,10 +37,12 @@ except ImportError:
 class InvalidCategory(Exception): pass
 class OptionsMissing(Exception): pass
 class AuthenticationError(Exception): pass
+class RequestError(Exception): pass
 
 EXIT_CODES = {
     OptionsMissing: 2,
     InvalidCategory: 3,
+    RequestError: 3,
     AuthenticationError: 4,
     oauth2client.client.FlowExchangeError: 4,
     NotImplementedError: 5,
@@ -74,6 +77,8 @@ def get_category_id(category):
     """Return category ID from its name."""
     if category:
         if category in youtube_upload.categories.IDS:
+            ncategory = youtube_upload.categories.IDS[category]
+            debug("Using category ID: {0} ({1})".format(category, ncategory))
             return str(youtube_upload.categories.IDS[category])
         else:
             msg = "{0} is not a valid category".format(category)
@@ -104,8 +109,11 @@ def upload_video(youtube, options, video_path, total_videos, index):
     }
 
     debug("Start upload: {0} ({1})".format(video_path, complete_title))
-    video_id = youtube_upload.upload_video.upload(youtube, video_path, 
-        request_body, progress_callback=progress.callback)
+    try:
+        video_id = youtube_upload.upload_video.upload(youtube, video_path, 
+            request_body, progress_callback=progress.callback)
+    except apiclient.errors.HttpError, error:
+        raise RequestError("Server response was: {0}".format(error.content.strip()))
     progress.finish()
     return video_id
 

+ 1 - 2
youtube_upload/upload_video.py

@@ -7,8 +7,7 @@ import httplib2
 import lib
 
 RETRIABLE_EXCEPTIONS = [
-    IOError, googleapiclient.errors.ResumableUploadError,
-    httplib2.HttpLib2Error, httplib.NotConnected,
+    IOError, httplib2.HttpLib2Error, httplib.NotConnected,
     httplib.IncompleteRead, httplib.ImproperConnectionState,
     httplib.CannotSendRequest, httplib.CannotSendHeader,
     httplib.ResponseNotReady, httplib.BadStatusLine,