Repository navigation
fix: swap httpx transport for requests to avoid Reddit 403 - #20
kragent66-glitch wants to merge 2 commits 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 jackwener#13.
|
Also hitting this exact issue: a valid The |
|
Bumping this. As reported above, the Happy to rebase or adjust anything you'd like. Is there anything blocking review? |
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