diff options
author | coletdjnz <coletdjnz@protonmail.com> | 2022-01-23 19:11:32 +1300 |
---|---|---|
committer | coletdjnz <coletdjnz@protonmail.com> | 2022-01-23 19:11:32 +1300 |
commit | 87e8e8a7d02b546ce6b8e34f502b8815b953f8cb (patch) | |
tree | 31f95d7648743978ccea9dacb91aa7596291776c | |
parent | e600a5c90817f4caac221679f6639211bba1f3a2 (diff) |
[youtube:api] Do not use seek when reading HTTPError response
Authored-by: coletdjnz
-rw-r--r-- | yt_dlp/extractor/youtube.py | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/yt_dlp/extractor/youtube.py b/yt_dlp/extractor/youtube.py index 0d42c2a89..98f02331c 100644 --- a/yt_dlp/extractor/youtube.py +++ b/yt_dlp/extractor/youtube.py @@ -760,13 +760,15 @@ class YoutubeBaseInfoExtractor(InfoExtractor): note='%s%s' % (note, ' (retry #%d)' % count if count else '')) except ExtractorError as e: if isinstance(e.cause, network_exceptions): - if isinstance(e.cause, compat_HTTPError) and not is_html(e.cause.read(512)): - e.cause.seek(0) - yt_error = try_get( - self._parse_json(e.cause.read().decode(), item_id, fatal=False), - lambda x: x['error']['message'], compat_str) - if yt_error: - self._report_alerts([('ERROR', yt_error)], fatal=False) + if isinstance(e.cause, compat_HTTPError): + first_bytes = e.cause.read(512) + if not is_html(first_bytes): + yt_error = try_get( + self._parse_json( + self._webpage_read_content(e.cause, None, item_id, prefix=first_bytes) or '{}', item_id, fatal=False), + lambda x: x['error']['message'], compat_str) + if yt_error: + self._report_alerts([('ERROR', yt_error)], fatal=False) # Downloading page may result in intermittent 5xx HTTP error # Sometimes a 404 is also recieved. See: https://github.com/ytdl-org/youtube-dl/issues/28289 # We also want to catch all other network exceptions since errors in later pages can be troublesome |