【问题标题】:Forbidden Reddit API call - Search within subreddit禁止 Reddit API 调用 - 在 subreddit 内搜索
【发布时间】:2021-10-05 19:18:27
【问题描述】:

我正在对 Reddit API 进行 API 调用并收到以下响应:

{'message': 'Forbidden', 'error': 403}

我的问题是为什么?当我在浏览器中访问此 URL 时,我得到了预期的 JSON:https://www.reddit.com/r/Charlottesville/search.json?q=food&restrict_sr=on

我已经设置了我的身份验证和所有内容,并发出了许多成功的 API 请求。我的标题是正确的。 当我运行以下代码时,我得到“禁止”响应:

#### Search within Subreddit

res = requests.get('https://www.reddit.com/r/Charlottesville/search.json?q=food&restrict_sr=on',
                   headers=headers)

print(res.json())

【问题讨论】:

  • 请求 documentation 显示将查询参数作为 params= arg 传递,而不是直接在 url 中硬编码。

标签: python python-requests reddit


【解决方案1】:

我的错误非常简单。应向oauth.reddit.com 发出经过正确身份验证的请求,因此我的格式正确的 URL 是:

https://oauth.reddit.com/r/Charlottesville/search.json?q=food&restrict_sr=on

它有效!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-06
    • 2014-02-22
    • 2022-12-28
    • 2013-12-03
    • 2014-02-22
    • 2019-05-30
    • 1970-01-01
    相关资源
    最近更新 更多