【问题标题】:OAuthException in Twitter with Flask, using OAuthlib.client使用 Flask 的 Twitter 中的 OAuthException,使用 OAuthlib.client
【发布时间】:2015-05-17 02:46:31
【问题描述】:

如果他/她使用 Twitter 登录,我正在尝试重定向一个人。 所以,在我的观点中:

    @twitter.tokengetter
    def get_twitter_token():
      if 'twitter_oauth' in flask.session:
      resp = flask.session['twitter_oauth']
    return resp['oauth_token'], resp['oauth_token_secret']


    @app.before_request
    def before_request():
      flask.g.user = None
      if 'twitter_oauth' in flask.session:
      flask.g.user = flask.session['twitter_oauth']

    @app.route('/login')
    def login():
      callback_url = flask.url_for('oauthorized', next=flask.request.args.get('next'))
    return twitter.authorize(callback=callback_url or flask.request.referrer or None)

    @app.route('/logout')
    def logout():
      flask.session.pop('twitter_oauth', None)
      return redirect(flask.url_for('index'))

    @app.route('/oauthorized')
    def oauthorized():
      resp = twitter.authorized_response()
      if resp is None:
        flask.flash('You denied the reques to sign in')
      else:
        flask.session['twitter_oauth'] = resp
      return flask.redirect(flask.url_for('success'))

我已经在我的 configs.py 中配置了 de TW_APP_ID 和 TW_APP_SECRET 值,当我执行时,它只会让我感到震惊

       flask_oauthlib.client.OAuthException
       OAuthException: Failed to generate request token

这是为了什么?我能做什么?

谢谢

【问题讨论】:

  • 很抱歉,如果有错误的识别错误。我检查了我的代码,一切都很好。

标签: python twitter oauth flask


【解决方案1】:

Flask-OAuthlib 示例已损坏。它们已在https://github.com/lepture/flask-oauthlib/issues/90 中修复。

你必须处理isinstance(resp, OAuthException)的情况。

检查此提交以了解对示例所做的更改:https://github.com/PyBossa/pybossa/commit/26ec807e321da2f87e1ab44149f5b40ae04bf8bd

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-05-31
  • 2013-04-22
  • 2013-09-07
  • 2018-07-14
  • 2014-10-03
  • 2013-01-10
  • 1970-01-01
相关资源
最近更新 更多