1

I'm trying to set up oauth in Django using Tweepy. I am getting the following error.

AttributeError at /auth/

'dict' object has no attribute 'key'

This occurs in the following code when I try to store the request token for later access when the user is forwarded to the callback 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)

I am new to Python and Django, does this error mean that the oauth.request_token is null? Could it be a problem with my callback url? Do I need to forward port 8000? Any help or pointers would be much appreciated!

1 Answer 1

1

I changed this line of code:

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

to this:

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

... after reading this documentation. And now it works!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.