Skip to content

search: www.reddit.com/search.json now returns 403 "Blocked"; api.reddit.com/search works as fallback #27

Open

Description

@zsh20000414

Summary

rdt search always fails with code: forbidden (Search failed: Access forbidden: Resource). Reddit now returns 403 Blocked for www.reddit.com/search.json and /r/<sub>/search.json, while other .json listings still work through the same httpx transport and cookies. https://api.reddit.com/search still returns the same Listing JSON, so it works as a drop-in fallback.

Environment

  • rdt-cli 0.4.1 (latest on PyPI), installed via pipx, Python 3.14, macOS
  • Authenticated (rdt status → authenticated: true, 7 cookies)

Reproduce

$ rdt -v search "test" --limit 1
GET https://www.reddit.com/search.json?q=test&sort=relevance&t=all&limit=1&restrict_sr=off&raw_json=1 "HTTP/1.1 403 Blocked"
ok: false
error:
  code: forbidden
  message: 'Search failed: Access forbidden: Resource'

Endpoint matrix (same cookies, same Chrome UA, plain httpx)

URL Status
www.reddit.com/r/popular.json 200 JSON
www.reddit.com/search.json?q=test 403
www.reddit.com/r/python/search.json?q=test&restrict_sr=on 403
www.reddit.com/r/all/search.json?q=test 403
old.reddit.com/search.json?q=test 403
www.reddit.com/search.rss?q=test 200 Atom
www.reddit.com/search/?q=test 200 HTML
api.reddit.com/search?q=test&raw_json=1 200 JSON (same Listing shape)
api.reddit.com/r/stocks/search?q=nvidia&restrict_sr=on 200 JSON

urllib.request with the same cookies also gets 403 on search.json, and httpx gets 200 on popular.json and api.reddit.com/search. So this block looks endpoint-specific, not tied to the httpx TLS fingerprint. Swapping the HTTP client (#20, #24, #26) may help other 403s (#13), but probably won't fix search on its own. I haven't tested curl_cffi impersonation against search.json.

Suggested fix

Fall back to api.reddit.com when search.json returns 403. This minimal local patch works for me: global and subreddit search, plus --json output, are all unchanged.

# rdt_cli/constants.py
 SEARCH_URL = "/search.json"
 SUBREDDIT_SEARCH_URL = "/r/{subreddit}/search.json"
+API_FALLBACK_BASE_URL = "https://api.reddit.com"

# rdt_cli/client.py  (RedditClient.search)
-        return self._get(url, params=params)
+        try:
+            return self._get(url, params=params)
+        except ForbiddenError:
+            logger.info("search.json forbidden, retrying via %s", API_FALLBACK_BASE_URL)
+            return self._get(API_FALLBACK_BASE_URL + url.removesuffix(".json"), params=params)

(plus importing ForbiddenError and API_FALLBACK_BASE_URL in client.py). The same fallback could apply to export, which goes through search().

Related: #13

Activity

  1. derekhsu commented on Nov 6, 2026

    @derekhsu

    Confirmed on a second machine (macOS 14.8.4, rdt-cli 0.4.1 from PyPI, 8 browser cookies): with the same cookies api.reddit.com/search and api.reddit.com/r/<sub>/search both return 200 Listing JSON while www.reddit.com/.../search.json returns the 403 block page. So the fallback in #28 works for global and subreddit-scoped search — I applied its two source hunks to a clean 0.4.1 install and rdt search came back green end to end. Since 0.4.1 is still the latest PyPI release, nothing installable can search right now; merging #28 into 0.4.2 would fix it for everyone.

  2. added a commit that references this issue on Nov 28, 2026
    1735fa6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions