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

* see https://github.com/yt-dlp/yt-dlp/issues/8816
pull/29845/head
dirkf 2 months ago
parent 80cb917ef6
commit 05aa2ad2f8

@ -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)

Loading…
Cancel
Save