Browse Source

use get_encoding in response debug

Arnau Sanchez 8 years ago
parent
commit
ed5209e4cc
2 changed files with 5 additions and 5 deletions
  1. 3 4
      youtube_upload/lib.py
  2. 2 1
      youtube_upload/main.py

+ 3 - 4
youtube_upload/lib.py

@@ -16,6 +16,9 @@ def default_sigint():
     finally:
         signal.signal(signal.SIGINT, original_sigint_handler)
         
+def get_encoding():
+    return locale.getpreferredencoding()
+    
 def to_utf8(s):
     """Re-encode string from the default system encoding to UTF-8."""
     current = locale.getpreferredencoding()
@@ -42,10 +45,6 @@ def catch_exceptions(exit_codes, fun, *args, **kwargs):
         debug("[{0}] {1}".format(exc.__class__.__name__, exc))
         return exit_codes[exc.__class__]
 
-def get_encoding(fd):
-    """Guess terminal encoding."""
-    return fd.encoding or locale.getpreferredencoding()
-
 def first(it):
     """Return first element in iterable."""
     return it.next()

+ 2 - 1
youtube_upload/main.py

@@ -244,7 +244,8 @@ def main(arguments):
     try:
         run_main(parser, options, args)
     except googleapiclient.errors.HttpError as error:
-        raise RequestError("Server response: {0}".format(bytes.decode(error.content).strip()))
+        response = bytes.decode(error.content, encoding=lib.get_encoding()).strip()
+        raise RequestError("Server response: {0}".format(response))
 
 def run():
     sys.exit(lib.catch_exceptions(EXIT_CODES, main, sys.argv[1:]))