]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/utils/_utils.py
[cleanup] Fix misc bugs (#8968)
[yt-dlp.git] / yt_dlp / utils / _utils.py
index d8b74423aab3de438f5617d2c79ba32d9ab5467a..49944e9d2b32493b0c16fabfb3463052ad9bdc79 100644 (file)
@@ -1424,7 +1424,8 @@ def write_string(s, out=None, encoding=None):
         s = re.sub(r'([\r\n]+)', r' \1', s)
 
     enc, buffer = None, out
-    if 'b' in getattr(out, 'mode', ''):
+    # `mode` might be `None` (Ref: https://github.com/yt-dlp/yt-dlp/issues/8816)
+    if 'b' in (getattr(out, 'mode', None) or ''):
         enc = encoding or preferredencoding()
     elif hasattr(out, 'buffer'):
         buffer = out.buffer