mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2026-02-20 07:26:04 +00:00
[ie/twitter] Fix error handling (#15993)
Closes #15963 Authored by: bashonly
This commit is contained in:
@@ -131,11 +131,16 @@ class TwitterBaseIE(InfoExtractor):
|
|||||||
video_id, headers=headers, query=query, expected_status=allowed_status,
|
video_id, headers=headers, query=query, expected_status=allowed_status,
|
||||||
note=f'Downloading {"GraphQL" if graphql else "legacy API"} JSON')
|
note=f'Downloading {"GraphQL" if graphql else "legacy API"} JSON')
|
||||||
|
|
||||||
if result.get('errors'):
|
if errors := traverse_obj(result, ('errors', ..., {dict})):
|
||||||
errors = ', '.join(set(traverse_obj(result, ('errors', ..., 'message', {str}))))
|
error_msg = ', '.join(set(traverse_obj(errors, (..., 'message', {str}))))
|
||||||
if errors and 'not authorized' in errors:
|
# An error with the message 'Dependency: Unspecified' is a false positive
|
||||||
self.raise_login_required(remove_end(errors, '.'))
|
# See https://github.com/yt-dlp/yt-dlp/issues/15963
|
||||||
raise ExtractorError(f'Error(s) while querying API: {errors or "Unknown error"}')
|
if len(errors) == 1 and 'dependency: unspecified' in error_msg.lower():
|
||||||
|
self.write_debug(f'Ignoring error message: "{error_msg}"')
|
||||||
|
elif 'not authorized' in error_msg.lower():
|
||||||
|
self.raise_login_required(remove_end(error_msg, '.'))
|
||||||
|
else:
|
||||||
|
raise ExtractorError(f'Error(s) while querying API: {error_msg or "Unknown error"}')
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@@ -1078,7 +1083,7 @@ class TwitterIE(TwitterBaseIE):
|
|||||||
raise ExtractorError(f'Twitter API says: {cause or "Unknown error"}', expected=True)
|
raise ExtractorError(f'Twitter API says: {cause or "Unknown error"}', expected=True)
|
||||||
elif typename == 'TweetUnavailable':
|
elif typename == 'TweetUnavailable':
|
||||||
reason = result.get('reason')
|
reason = result.get('reason')
|
||||||
if reason == 'NsfwLoggedOut':
|
if reason in ('NsfwLoggedOut', 'NsfwViewerHasNoStatedAge'):
|
||||||
self.raise_login_required('NSFW tweet requires authentication')
|
self.raise_login_required('NSFW tweet requires authentication')
|
||||||
elif reason == 'Protected':
|
elif reason == 'Protected':
|
||||||
self.raise_login_required('You are not authorized to view this protected tweet')
|
self.raise_login_required('You are not authorized to view this protected tweet')
|
||||||
|
|||||||
Reference in New Issue
Block a user