Fix cannot get topics error by adding User-Agent header - #83
Open
motangpuar wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
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-Agentheader 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
:LeetCodeListfails with:caused by
cannot get topicsin leetcode.py.get_topics_and_companies()requestsLC_PROBLEM_SET_ALLand only returns data on a 200 response. That request was failing.Cause
_make_headers()builds every request without aUser-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-Agentto_make_headers().Testing
Confirmed
:LeetCodeSignInfollowed by:LeetCodeListnow populates the problem list correctly. Before the change, it failed reliably with the error above.