Fix for when stdout/stderr encoding is None

Closes #2711
This commit is contained in:
pukkandan 2022-02-17 19:21:59 +05:30
parent ffa89477ea
commit 5c10453827
No known key found for this signature in database
GPG Key ID: 7EEE9E1E817D0A39
1 changed files with 2 additions and 1 deletions

View File

@ -888,7 +888,8 @@ class YoutubeDL(object):
def _format_text(self, handle, allow_colors, text, f, fallback=None, *, test_encoding=False): def _format_text(self, handle, allow_colors, text, f, fallback=None, *, test_encoding=False):
if test_encoding: if test_encoding:
original_text = text original_text = text
encoding = self.params.get('encoding') or getattr(handle, 'encoding', 'ascii') # handle.encoding can be None. See https://github.com/yt-dlp/yt-dlp/issues/2711
encoding = self.params.get('encoding') or getattr(handle, 'encoding', None) or 'ascii'
text = text.encode(encoding, 'ignore').decode(encoding) text = text.encode(encoding, 'ignore').decode(encoding)
if fallback is not None and text != original_text: if fallback is not None and text != original_text:
text = fallback text = fallback