Description
The client.get_latest_timeline API occasionally throws an error: KeyError: 'legacy'
My version number is: 2.3.3
Error stack trace (Note: I modified the code, causing line numbers to shift slightly compared to the repository):
`
Traceback (most recent call last):
File "main.py", line 221, in load_like_twitters_v2
File "lib\twitter.py", line 141, in follow_tweets
File "twikit\client\client.py", line 2070, in get_latest_timeline
File "twikit\tweet.py", line 576, in tweet_from_data
File "twikit\user.py", line 92, in init
KeyError: 'legacy'
`
JSON data of the tweet I printed at the error location
{ "__typename": "Tweet", "rest_id": "1912966797470634404", "core": { "user_results": { "result": { "__typename": "User", "id": "VXNlcjo3MTAyNjEyMg==", "rest_id": "71026122", "affiliates_highlighted_label": {}, "has_graduated_access": true, "profile_image_shape": "Square" } } }, "card": { "rest_id": "card://1912965772319543296", "legacy": { "binding_values": [{ "key": "unified_card", "value": { "string_value": "{\"type\":\"video_website\",\"component_objects\":{\"details_1\":{\"type\":\"details\",\"data\":{\"title\":{\"content\":\"only on the app\",\"is_rtl\":false},\"subtitle\":{\"content\":\"smart.link\",\"is_rtl\":false},\"destination\":\"override_browser_with_docked_media_1\"}},\"media_1\":{\"type\":\"media\",\"data\":{\"id\":\"13_1912956988473962496\",\"destination\":\"browser_with_docked_media_1\"}}},\"destination_objects\":{\"browser_with_docked_media_1\":{\"type\":\"browser_with_docked_media\",\"data\":{\"url_data\":{\"url\":\"https://smart.link/qg3of07r2bsuw\",\"vanity\":\"smart.link\"},\"media_id\":\"13_1912956988473962496\"}},\"override_browser_with_docked_media_1\":{\"type\":\"browser\",\"data\":{\"url_data\":{\"url\":\"https://smart.link/qg3of07r2bsuw\",\"vanity\":\"smart.link\"}}}},\"components\":[\"media_1\",\"details_1\"],\"media_entities\":{\"13_1912956988473962496\":{\"id\":1912956988473962496,\"id_str\":\"1912956988473962496\",\"indices\":[0,0],\"media_url\":\"\",\"media_url_https\":\"https://pbs.twimg.com/amplify_video_thumb/1912956988473962496/img/KIDnHSPtvaZcSmHz.jpg\",\"url\":\"\",\"display_url\":\"\",\"expanded_url\":\"\",\"type\":\"video\",\"original_info\":{\"width\":1080,\"height\":1080},\"sizes\":{\"medium\":{\"w\":1080,\"h\":1080,\"resize\":\"fit\"},\"large\":{\"w\":1080,\"h\":1080,\"resize\":\"fit\"},\"thumb\":{\"w\":150,\"h\":150,\"resize\":\"crop\"},\"small\":{\"w\":680,\"h\":680,\"resize\":\"fit\"}},\"source_user_id\":71026122,\"source_user_id_str\":\"71026122\",\"video_info\":{\"aspect_ratio\":[1,1],\"duration_millis\":15015,\"variants\":[{\"content_type\":\"application/x-mpegURL\",\"url\":\"https://video.twimg.com/amplify_video/1912956988473962496/pl/Wlo5Yy3whG_nqvKS.m3u8?tag=14&v=e1b\"},{\"bitrate\":432000,\"content_type\":\"video/mp4\",\"url\":\"https://video.twimg.com/amplify_video/1912956988473962496/vid/avc1/320x320/C20IvW6FHSd2Sktl.mp4?tag=14\"},{\"bitrate\":832000,\"content_type\":\"video/mp4\",\"url\":\"https://video.twimg.com/amplify_video/1912956988473962496/vid/avc1/540x540/0kou4Vd7twSazvyR.mp4?tag=14\"},{\"bitrate\":1280000,\"content_type\":\"video/mp4\",\"url\":\"https://video.twimg.com/amplify_video/1912956988473962496/vid/avc1/720x720/mFYFB47YL3rGstAa.mp4?tag=14\"}]},\"media_key\":\"13_1912956988473962496\",\"ext\":{\"mediaColor\":{\"r\":{\"ok\":{\"palette\":[{\"rgb\":{\"red\":80,\"green\":108,\"blue\":49},\"percentage\":53.85},{\"rgb\":{\"red\":173,\"green\":207,\"blue\":252},\"percentage\":18.33},{\"rgb\":{\"red\":90,\"green\":35,\"blue\":125},\"percentage\":9.01},{\"rgb\":{\"red\":63,\"green\":49,\"blue\":36},\"percentage\":7.53},{\"rgb\":{\"red\":159,\"green\":159,\"blue\":161},\"percentage\":2.75}]}},\"ttl\":-1}}}}},\"experiment_signals\":{}}", "type": "STRING" } }, { "key": "card_url", "value": { "scribe_key": "card_url", "string_value": "https://twitter.com", "type": "STRING" } } ], "card_platform": { "platform": { "audience": { "name": "production" }, "device": { "name": "Swift", "version": "12" } } }, "name": "unified_card", "url": "card://1912965772319543296", "user_refs_results": [] } }, "unmention_data": {}, "edit_control": { "edit_tweet_ids": ["1912966797470634404"], "editable_until_msecs": "1744925400000", "is_edit_eligible": false, "edits_remaining": "5" }, "is_translatable": false, "views": { "count": "4980604", "state": "EnabledWithCount" }, "source": "<a href=\"https://help.twitter.com/en/using-twitter/how-to-tweet#source-labels\" rel=\"nofollow\">advertiser-interface</a>", "legacy": { "bookmark_count": 480, "bookmarked": false, "created_at": "Thu Apr 17 20:30:00 +0000 2025", "conversation_id_str": "1912966797470634404", "display_text_range": [0, 74], "entities": { "hashtags": [], "symbols": [], "timestamps": [], "urls": [], "user_mentions": [] }, "favorite_count": 1854, "favorited": false, "full_text": "Birdie Wings are powered by Nether Flame Sauce fyi. movie and meal out now", "is_quote_status": false, "lang": "en", "quote_count": 22, "reply_count": 52, "retweet_count": 75, "retweeted": false, "scopes": { "followers": false }, "user_id_str": "71026122", "id_str": "1912966797470634404" } }
Location where I printed the JSON:

Let me know if you need further adjustments!