【发布时间】: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