我使用PRAW包从reddit读取信息。PS: client_id, client_secret和user_agent的值传递正确
import praw
from prawcore.exceptions import ResponseException
reddit = praw.Reddit(
client_id="xxxxxxx",
client_secret="xxxxxxxxxxxxxxx",
user_agent="xxxxxxxxxxxxxx",
)
print (reddit.read_only)
subreddit = reddit.subreddit("redditdev")
print(subreddit.display_name) # output: redditdev
print(subreddit.title) # output: reddit development
print(subreddit.description)
实例reddit似乎成功创建,因为我可以打印read_only
属性和display_name
属性的值。然而,当打印title
属性时,我得到401 HTTP响应错误。
True
redditdev
Traceback (most recent call last):
File "/Users/sanjose/PycharmProjects/pubReddit/prawC/prawMain.py", line 13, in <module>
print(subreddit.title) # output: reddit development
............
............
File "/Users/sanjose/PycharmProjects/pubReddit/venv/lib/python3.7/site-packages/prawcore/auth.py", line 36, in _post
raise ResponseException(response)
prawcore.exceptions.ResponseException: received 401 HTTP response
我故意不传递用户id和密码,因为我希望仅在只读模式下使用它。我是否错过了一些设置,或者title
属性是否需要身份验证?
我有同样的问题,我很确定这是因为我做了一个web应用程序,而不是一个脚本。我通过制作一个新的reddit应用程序(你可以在这里制作一个reddit应用程序)并选择脚本选项而不是web应用程序选项来解决这个问题。