fix: swap httpx transport for requests to avoid Reddit 403 - #20
Open
kragent66-glitch wants to merge 1 commit into
Open
fix: swap httpx transport for requests to avoid Reddit 403#20kragent66-glitch wants to merge 1 commit into
kragent66-glitch wants to merge 1 commit into
Conversation
Reddit's bot detection fingerprints the httpx TLS/HTTP stack and returns a 403 challenge page even with a valid reddit_session cookie, while urllib3/requests passes. Replace the httpx.Client with a requests.Session, add manual BASE_URL joining (requests has no base_url), pass an explicit timeout, and catch requests exceptions. Verified live: /r/python/top.json returns posts; /api/v1/me no longer 403s. Closes public-clis#13.
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.
Summary
Reddit's bot detection fingerprints the httpx TLS/HTTP stack and returns a 403 challenge page even with a valid
reddit_sessioncookie. Replacing thehttpx.Clientwith arequests.Sessionfixes it βurllib3/requestspasses Reddit's fingerprint checks.Closes #13 (same repro: valid cookie works with curl/urllib, httpx gets 403).
Changes
rdt_cli/transports.py:httpx.Clientβrequests.Session(headers + cookies copied,max_redirects=10)BASE_URLjoining for relative URLs (requestshas nobase_url)timeout=self.config.timeoutper request (requestshas no default)httpx.TimeoutException/NetworkErrorβrequests.Timeout/ConnectionErrorpyproject.toml:httpx>=0.27βrequests>=2.31(httpx no longer imported anywhere)Why requests instead of patching httpx?
requestsis a lighter, ubiquitous dependency already used transitively by most Python stacks.Verification
pytest tests/β 123 passed (66 deselected)GET /r/python/top.json?limit=2β returns posts (no 403)GET /api/v1/meβ no 403, no exception