From 3f7965105d8d2048359e67c1e8b8ebd51588143b Mon Sep 17 00:00:00 2001 From: pukkandan Date: Sun, 30 Jul 2023 03:18:10 +0530 Subject: [PATCH] [utils] HTTPHeaderDict: Handle byte values --- test/test_utils.py | 2 ++ yt_dlp/utils/networking.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/test/test_utils.py b/test/test_utils.py index 453a01a1c..91e3ffd39 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -2344,6 +2344,8 @@ Line 1 def test_http_header_dict(self): headers = HTTPHeaderDict() + headers['ytdl-test'] = b'0' + self.assertEqual(list(headers.items()), [('Ytdl-Test', '0')]) headers['ytdl-test'] = 1 self.assertEqual(list(headers.items()), [('Ytdl-Test', '1')]) headers['Ytdl-test'] = '2' diff --git a/yt_dlp/utils/networking.py b/yt_dlp/utils/networking.py index bbcea84d2..ba0493cc2 100644 --- a/yt_dlp/utils/networking.py +++ b/yt_dlp/utils/networking.py @@ -65,6 +65,8 @@ class HTTPHeaderDict(collections.UserDict, dict): self.update(kwargs) def __setitem__(self, key, value): + if isinstance(value, bytes): + value = value.decode('latin-1') super().__setitem__(key.title(), str(value)) def __getitem__(self, key):