Python Praw:API登录失败,出现客户端错误

Python Praw:API登录失败,出现客户端错误,python,google-app-engine,http-status-code-403,reddit,praw,Python,Google App Engine,Http Status Code 403,Reddit,Praw,我无法使用下面的代码登录到我自己的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' s

我无法使用下面的代码登录到我自己的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)

您的代码不必要地过于复杂,只需使用PRAW登录即可。推荐的方法是让
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
用户代理的要求如下:

将客户端的用户代理字符串更改为唯一和描述性的内容,包括目标平台、唯一的应用程序标识符、版本字符串以及作为联系信息的用户名,格式如下:
:(by/u/)

-
Example:User-Agent:android:com.Example.myredditapp:v1.2.3(by/u/kemithe)

  • 许多默认用户代理(如“Python/urllib”或“Java”)都受到严格限制,以鼓励用户代理字符串具有唯一性和描述性
  • 包括版本号并在您构建应用程序时进行更新,使我们能够安全地阻止应用程序的旧错误/损坏版本
  • 永远不要对你的用户代理撒谎。这包括欺骗流行浏览器和欺骗其他机器人。我们将禁止带有极端偏见的说谎者
如果您将来有任何问题,请毫不犹豫地提出,作为对本答案的评论