[YoutubeDL] Make sure we really, really get out the encoding string
authorPhilipp Hagemeister <phihag@phihag.de>
Wed, 23 Jul 2014 00:24:50 +0000 (02:24 +0200)
committerPhilipp Hagemeister <phihag@phihag.de>
Wed, 23 Jul 2014 00:24:52 +0000 (02:24 +0200)
Fixes #3326
Apparently, on some platforms, even outputting this fails already.

youtube_dl/YoutubeDL.py

index 686988fe5bdaa71f8dd346b3b90795d213b92b7c..f5ca33d453a89359405d468dc994337dfec7910b 100755 (executable)
@@ -1234,14 +1234,21 @@ class YoutubeDL(object):
         if not self.params.get('verbose'):
             return
 
-        write_string(
+        encoding_str = (
             '[debug] Encodings: locale %s, fs %s, out %s, pref %s\n' % (
                 locale.getpreferredencoding(),
                 sys.getfilesystemencoding(),
                 sys.stdout.encoding,
-                self.get_encoding()),
-            encoding=None
-        )
+                self.get_encoding()))
+        try:
+            write_string(encoding_str, encoding=None)
+        except:
+            errmsg = 'Failed to write encoding string %r' % encoding_str
+            try:
+                sys.stdout.write(errmsg)
+            except:
+                pass
+            raise IOError(errmsg)
 
         self._write_string('[debug] youtube-dl version ' + __version__ + '\n')
         try: