【问题标题】:Attribute Error Django using tweepy oauth使用 tweepy oauth 的属性错误 Django
【发布时间】:2015-06-02 21:28:22
【问题描述】:

我正在尝试使用 Tweepy 在 Django 中设置 oauth。我收到以下错误。

/auth/处的AttributeError

'dict'对象没有属性'key'

当用户被转发到回调 url (http://localhost:8000/callback) 时,当我尝试存储请求令牌以供以后访问时,会在以下代码中发生这种情况。

def auth(request):
    # start the OAuth process, set up a handler with our details
    oauth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET, CALLBACK)
    # direct the user to the authentication url
    # if user is logged-in and authorized then transparently goto the callback URL
    try:
        auth_url = oauth.get_authorization_url()
    except tweepy.TweepError:
        return HttpResponse('error', status=500)
    # store the request token
    request.session['unauthed_token_tw'] = (oauth.request_token.key, oauth.request_token.secret) 
    return HttpResponseRedirect(auth_url)

我是 Python 和 Django 的新手,这个错误是否意味着 oauth.request_token 为空?我的回调网址可能有问题吗?我需要转发8000端口吗?任何帮助或指点将不胜感激!

【问题讨论】:

    标签: python django oauth tweepy


    【解决方案1】:

    我改了这行代码:

    request.session['unauthed_token_tw'] = (oauth.request_token.key, oauth.request_token.secret)
    

    到这里:

    request.session['unauthed_token_tw'] = oauth.request_token
    

    ...阅读此documentation 后。现在它可以工作了!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-09
      • 2018-05-01
      • 2013-11-03
      • 1970-01-01
      • 2014-07-14
      相关资源
      最近更新 更多