mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-12-12 14:26:49 +01:00
[youtube] Extract error messages from HTTPError response (#644)
Authored by: coletdjnz
This commit is contained in:
parent
0715f7e19b
commit
641ad5d813
@ -38,6 +38,7 @@
|
|||||||
format_field,
|
format_field,
|
||||||
int_or_none,
|
int_or_none,
|
||||||
intlist_to_bytes,
|
intlist_to_bytes,
|
||||||
|
is_html,
|
||||||
mimetype2ext,
|
mimetype2ext,
|
||||||
network_exceptions,
|
network_exceptions,
|
||||||
orderedSet,
|
orderedSet,
|
||||||
@ -723,11 +724,11 @@ def _extract_alerts(cls, data):
|
|||||||
if message:
|
if message:
|
||||||
yield alert_type, message
|
yield alert_type, message
|
||||||
|
|
||||||
def _report_alerts(self, alerts, expected=True):
|
def _report_alerts(self, alerts, expected=True, fatal=True):
|
||||||
errors = []
|
errors = []
|
||||||
warnings = []
|
warnings = []
|
||||||
for alert_type, alert_message in alerts:
|
for alert_type, alert_message in alerts:
|
||||||
if alert_type.lower() == 'error':
|
if alert_type.lower() == 'error' and fatal:
|
||||||
errors.append([alert_type, alert_message])
|
errors.append([alert_type, alert_message])
|
||||||
else:
|
else:
|
||||||
warnings.append([alert_type, alert_message])
|
warnings.append([alert_type, alert_message])
|
||||||
@ -793,6 +794,13 @@ def _extract_response(self, item_id, query, note='Downloading API JSON', headers
|
|||||||
note='%s%s' % (note, ' (retry #%d)' % count if count else ''))
|
note='%s%s' % (note, ' (retry #%d)' % count if count else ''))
|
||||||
except ExtractorError as e:
|
except ExtractorError as e:
|
||||||
if isinstance(e.cause, network_exceptions):
|
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)
|
||||||
# Downloading page may result in intermittent 5xx HTTP error
|
# 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
|
# 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
|
# We also want to catch all other network exceptions since errors in later pages can be troublesome
|
||||||
|
Loading…
Reference in New Issue
Block a user