Skip to content

fix: use browser headers for HTML discovery pages in refresh_query_ids - #76

Open
yonran wants to merge 1 commit into
tfriedel:mainfrom
yonran:fix/scraper-browser-headers
Open

fix: use browser headers for HTML discovery pages in refresh_query_ids#76
yonran wants to merge 1 commit into
tfriedel:mainfrom
yonran:fix/scraper-browser-headers

Conversation

@yonran

@yonran yonran commented Jun 26, 2026

Copy link
Copy Markdown

Summary

  • refresh_query_ids was passing the API auth client (with Bearer token and x-csrf-token) when fetching Twitter's HTML discovery pages, causing 401 responses
  • Twitter's discovery pages (x.com, x.com/explore, etc.) only serve HTML to browser-like requests; API auth headers cause them to reject the request
  • Fix: use a dedicated httpx.AsyncClient with browser User-Agent/Accept headers for HTML page fetches, keeping the original client for subsequent API calls only
  • Also tries all configured discovery pages (not just the first), so the scraper can fall back to /explore or /notifications if the homepage returns a non-200
  • Added optional cookies= parameter so authenticated pages succeed where the unauthenticated homepage might not
  • Passes cookies= through in the refresh-ids command and in the Likes/Bookmarks sync flows

Test plan

  • Run tweethoarder refresh-ids — should succeed and print Refreshed N query IDs. instead of returning 0 IDs due to 401
  • Run tweethoarder sync likes and tweethoarder sync bookmarks — inline query ID refresh on 404 should work correctly

🤖 Generated with Claude Code

refresh_query_ids was passing the API auth client (Bearer token + x-csrf-token)
when fetching Twitter's HTML discovery pages, causing 401 responses. Twitter
only serves those pages to browser-like requests.

Fix: use a dedicated httpx client with browser User-Agent/Accept headers for
the HTML fetches. Also tries all configured discovery pages (not just the first)
so the scraper can fall back to /explore or /notifications if the homepage
returns a non-200. Pass cookies= through so authenticated pages succeed where
the unauthenticated homepage might not.

Also passes cookies= when refreshing query IDs in the Likes and Bookmarks
sync flows and in the refresh-ids command, so page fetches work for all callers.
@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@yonran, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 59 minutes and 47 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5e5c8787-c2e9-44cf-8981-a37e31ed15e7

📥 Commits

Reviewing files that changed from the base of the PR and between 77d0018 and e38cb23.

📒 Files selected for processing (3)
  • src/tweethoarder/cli/main.py
  • src/tweethoarder/cli/sync.py
  • src/tweethoarder/query_ids/scraper.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant