Skip to content

Fix cannot get topics error by adding User-Agent header - #83

Open
motangpuar wants to merge 1 commit into
ianding1:masterfrom
motangpuar:fix-user-agent-header
Open

Fix cannot get topics error by adding User-Agent header#83
motangpuar wants to merge 1 commit into
ianding1:masterfrom
motangpuar:fix-user-agent-header

Conversation

@motangpuar

Copy link
Copy Markdown

Problem

:LeetCodeList fails with:

Error detected while processing function leetcode#ListProblems:
line 31:
E684: List index out of range: 0

caused by cannot get topics in leetcode.py. get_topics_and_companies() requests LC_PROBLEM_SET_ALL and only returns data on a 200 response. That request was failing.

Cause

_make_headers() builds every request without a User-Agent. LeetCode's edge protection blocks or challenges requests that don't look like they came from a browser, so the topics/companies scrape returns a non-200 response even though the session is authenticated and other calls (sign-in, problem fetch) go through.

Fix

Add a standard browser User-Agent to _make_headers().

Testing

Confirmed :LeetCodeSignIn followed by :LeetCodeList now populates the problem list correctly. Before the change, it failed reliably with the error above.

Copilot AI lite review requested due to automatic review settings August 13, 2026 12:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses :LeetCodeList failures caused by get_topics_and_companies() receiving a non-200 response from LC_PROBLEM_SET_ALL, by making LeetCode requests look more like a browser request.

Changes:

  • Add a standard browser User-Agent header to _make_headers() so subsequent authenticated requests aren’t blocked/challenged by edge protection.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

2 participants