snscrape
snscrape copied to clipboard
Twitter `UserTweetsAndReplies` API may return deleted Tweets
Hello ! First of all, thank you very much for SNScrape, it's an awesome projet. Second, I'm sorry for my english. It's not my native language.
I'm using SNScrape in my Python code, but to simplify, I reproduced this issue in the CLI.
When scraping some users with TwitterProfileScraper
, the UserTweetsAndReplies
API may return deleted Tweet, causing SNScrape to crash with the following exception :
Traceback (most recent call last):
File "C:\...\snscrape\_cli.py", line 116, in _dump_locals_on_exception
yield
File "C:\...\snscrape\_cli.py", line 318, in main
for i, item in enumerate(scraper.get_items(), start = 1):
File "C:\...\snscrape\modules\twitter.py", line 1592, in get_items
yield from self._graphql_timeline_instructions_to_tweets(instructions)
File "C:\...\snscrape\modules\twitter.py", line 1313, in _graphql_timeline_instructions_to_tweets
yield self._graphql_timeline_tweet_item_result_to_tweet(entry['content']['itemContent']['tweet_results']['result'])
KeyError: 'result'
You can reproduce this exception by executing the following command : snscrape twitter-profile nicetomeet0308
In this case, the API returns Tweet ID 1547690599553241090, which has been deleted. Here is the content of the entry
variable in _graphql_timeline_instructions_to_tweets()
:
{'entryId': 'tweet-1547690599553241090',
'sortIndex': '1547690599553241090',
'content': {'entryType': 'TimelineTimelineItem',
'itemContent': {'itemType': 'TimelineTweet',
'tweet_results': {},
'tweetDisplayType': 'Tweet'}}
As you can see, tweet_results
is empty.
I tested this issue on a Windows 10 machine, and a Ubuntu 22.04 server, both with Python 3.10 and SNScrape 0.4.3.20220107.dev65+g46a6030 (Latest commit on the master
branch).
Thanks for reading me, and have a nice day !
Can confirm - here's my dump file (compressed with zstd):
https://transfer.archivete.am/Wmfs3/snscrape_locals_anmm9buj.zst