Repository navigation
fix(search): fall back to api.reddit.com when search.json is blocked - #28
robertn702 wants to merge 1 commit into
Conversation
www.reddit.com/search.json and /r/<sub>/search.json answer 403 for every session, so search and export fail with code: forbidden on 0.4.1. api.reddit.com serves the same Listing JSON for the same cookies. Closes jackwener#27
|
Independently verified on macOS — this fixes both search paths. Environment: rdt-cli 0.4.1 (PyPI, uv tool), Python 3.14, macOS 14.8.4, browser-cookie auth ( I applied the two source hunks from this PR to a clean 0.4.1 install and ran the real CLI: and the subreddit-scoped path: The fallback response is the same Listing JSON shape, so Two observations from the same investigation, outside this PR's scope:
0.4.1 is still the latest release on PyPI, so right now there is no installable version whose |
Auth - Find Reddit cookies in every profile of Firefox/LibreWolf (including the XDG ~/.config/mozilla/firefox location of Firefox 147+, snap, flatpak) and Chrome/Chromium/Brave/Edge/Vivaldi. Firefox DBs are read from a copy that includes the -wal file, so fresh logins are seen and the browser lock is avoided. Only logged-in sessions count (reddit_session, or a token_v2 JWT with sub=user); anonymous jars are skipped. Drops the uv subprocess path. Covers upstream jackwener#9, jackwener#16, jackwener#23. - RDT_COOKIE / RDT_SESSION / RDT_MODHASH env auth; public commands no longer extract browser cookies on their own (upstream jackwener#17). - rdt login reports the source and no longer claims "already authenticated" after silently extracting. Upstream fixes - search falls back to api.reddit.com when search.json is 403 (jackwener#27, jackwener#28). - comment sends api_type/thing_id/text and raises on json.errors (jackwener#14). Reading posts - read/upvote/save/comment accept reddit.com and redd.it post URLs. - read/show --markdown: post + full comment tree as Markdown; --article appends the linked page of link posts via the defuddle CLI. - morechildren requests are batched at 100 IDs (was 414 URI Too Long); when Reddit blocks the API (403), --expand-more warns and keeps loaded comments. - Error codes are no longer swallowed as Rich markup. Tests - Unit tests no longer write to the real ~/.config/rdt-cli. - New tests for browser discovery, env auth, Markdown, URL parsing, batching.
# Conflicts: # rdt_cli/client.py # tests/test_client.py
Search is broken in 0.4.1.
www.reddit.com/search.jsonand/r/<sub>/search.jsonanswer 403 ("You've been blocked by network security") for every session, while listings still work through the same transport and cookies.api.reddit.com/searchreturns the same Listing JSON for the same cookies.Closes #27.
What changed
rdt_cli/client.pyretriessearch()againstapi.reddit.comwhen the.jsonpath raisesForbiddenError. The retry drops the.jsonsuffix and sends the same params, so subreddit search, sort and time filters are unchanged.rdt_cli/constants.pyaddsAPI_FALLBACK_BASE_URL.tests/test_client.pyadds three tests. Two cover the fallback for global and subreddit search, one covers a non-403 error that should propagate without a retry.Testing
uv run ruff check .passes,uv run python -m pytest -qgives 126 passed, 66 deselected.Live check from this checkout with browser cookies.
uv run rdt search "python asyncio" -n 3anduv run rdt search "asyncio" -r python -s top -t year -n 2both return listings.rdt exportcallssearch(), so it's fixed as well.