[utils] `mode` might be `None` in `write_string()`

* see https://github.com/yt-dlp/yt-dlp/issues/8816
This commit is contained in:
dirkf 2024-03-11 15:52:02 +00:00
parent 80cb917ef6
commit 05aa2ad2f8
1 changed files with 2 additions and 1 deletions

View File

@ -3495,7 +3495,8 @@ def write_string(s, out=None, encoding=None):
if _windows_write_string(s, out):
return
if ('b' in getattr(out, 'mode', '')
# `mode` might be `None` (see https://github.com/yt-dlp/yt-dlp/issues/8816)
if ('b' in (getattr(out, 'mode', None) or '')
or sys.version_info[0] < 3): # Python 2 lies about mode of sys.stderr
byt = s.encode(encoding or preferredencoding(), 'ignore')
out.write(byt)