Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion twikit/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1523,7 +1523,7 @@ async def _get_more_replies(
results.append(tweet)

if entries[-1]['entryId'].startswith('cursor'):
next_cursor = entries[-1]['content']['itemContent']['value']
next_cursor = entries[-1]['content']['value']

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Use schema-tolerant cursor extraction here to avoid pagination breakage.

Line 1526 hardcodes content.value, but the same tweet-detail flow still reads content.itemContent.value at Line 1635. If payload shape differs between pages, one path can fail with KeyError and break reply pagination.

🔧 Proposed hardening
-        if entries[-1]['entryId'].startswith('cursor'):
-            next_cursor = entries[-1]['content']['value']
+        if entries[-1]['entryId'].startswith('cursor'):
+            cursor_content = entries[-1].get('content', {})
+            next_cursor = (
+                cursor_content.get('value')
+                or cursor_content.get('itemContent', {}).get('value')
+            )
+            if next_cursor is None:
+                _fetch_next_result = None
+                return Result(results, _fetch_next_result, None)
             _fetch_next_result = partial(self._get_more_replies, tweet_id, next_cursor)

Also apply the same fallback pattern at Line 1635 for consistency.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@twikit/client/client.py` at line 1526, The pagination cursor extraction
currently assumes entries[-1]['content']['value'] and later
entries[-1]['content']['itemContent']['value'] which can KeyError if payload
shape varies; update the extraction used for next_cursor (symbol: next_cursor
and the entries list) to be schema‑tolerant: attempt content['value'], then
content.get('itemContent', {}).get('value') (or equivalent safe lookups),
falling back to None if neither exists, and apply the same tolerant fallback
wherever content.itemContent.value is read (the later read around line with
content.itemContent.value) so both paths handle either shape without raising
KeyError.

_fetch_next_result = partial(self._get_more_replies, tweet_id, next_cursor)
else:
next_cursor = None
Expand Down