Fix KeyError on entity for inexistent Twitter accounts

This commit is contained in:
JustAnotherArchivist
2020-11-03 23:21:28 +00:00
parent 61a1ecffc5
commit 6d6411cc24

View File

@@ -477,6 +477,8 @@ class TwitterUserScraper(TwitterSearchScraper):
self._ensure_guest_token(f'https://twitter.com/{self._username}')
params = {'variables': json.dumps({'screen_name': self._username, 'withHighlightedLabel': True}, separators = (',', ':'))}
obj = self._get_api_data('https://api.twitter.com/graphql/-xfUfZsnR_zqjFd-IfrN5A/UserByScreenName', params = urllib.parse.urlencode(params, quote_via=urllib.parse.quote))
if not obj['data']:
return None
user = obj['data']['user']
rawDescription = user['legacy']['description']
description = self._render_text_with_urls(rawDescription, user['legacy']['entities']['description']['urls'])