我正在对Reddit API进行API调用,并收到以下响应:
{'message': 'Forbidden', 'error': 403}我的问题是为什么?当我在浏览器中访问这个网址时,我得到了预期的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())发布于 2021-10-08 14:25:47
我的错误很简单。应该向oauth.reddit.com发出经过正确身份验证的请求,因此我的格式正确的网址是:
https://oauth.reddit.com/r/Charlottesville/search.json?q=food&restrict_sr=on而且它起作用了!
https://stackoverflow.com/questions/69456130
复制相似问题