我无法使用下面的代码登录我自己的Reddit帐户。
错误讯息:
raise HTTPError(http_error_msg, response=self) HTTPError: 403 Client Error: Forbidden
有没有办法解决这个错误?
class PrawTest(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('Yo, imma redit bot!')
get_login= ConfigParser.ConfigParser()
get_login.read("logins.ini")
r = praw.Reddit(user_agent='Captain Reddit!')
r.login(get_login.get("login1", "username"),get_login.get("login1","password"))
app = webapp2.WSGIApplication([('/hype_shit_up', PrawTest)], debug=True)
答案 0 :(得分:0)
使用PRAW登录时,您的代码非常不必要地过于复杂。在the documentation中推荐的方式是让reddit = praw.Reddit('SOME-NAME-HERE')
登录。然后,在praw.ini
文件中,将其设置为如下所示:
[DEFAULT]
# A boolean to indicate whether or not to check for package updates.
check_for_updates=True
# Object to kind mappings
comment_kind=t1
message_kind=t4
redditor_kind=t2
submission_kind=t3
subreddit_kind=t5
# The URL prefix for OAuth-related requests.
oauth_url=https://oauth.reddit.com
# The URL prefix for regular requests.
reddit_url=https://www.reddit.com
# The URL prefix for short URLs.
short_url=https://redd.it
[SOME-NAME-HERE]
user_agent=USER-AGENT-HERE
username=REDDIT-ACCOUNT-USERNAME
password=REDDIT-ACCOUNT-PASSWORD
client_id=REDDIT-APP-CLIENT-ID
client_secret=REDDIT-APP-CLIENT-SECRET
找到用户代理的要求here:
将客户端的用户代理字符串更改为唯一且具有描述性的内容,包括目标平台,唯一应用程序标识符,版本字符串和用户名作为联系信息,格式如下:
<platform>:<app ID>:<version string> (by /u/<reddit username>)
- Example: User-Agent: android:com.example.myredditapp:v1.2.3 (by /u/kemitche)
如果您有任何未来的问题,请不要犹豫,将其作为对此答案的评论!