2
votes

I'm using the tweepy google app engine example here as the basis for my application: https://github.com/tweepy/examples/tree/master/appengine

The get_authorization_url() method triggers the 401 unauthorized exception.

template.render('oauth_example/main.html', {
                "authurl": auth.get_authorization_url(),
                "request_token": auth.request_token
                })

In console I get:

TweepError: HTTP Error 401: Unauthorized

Using the library from the python interpreter works fine:

import tweepy

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)

print auth.get_authorization_url()

prints out a valid authentication url. But the same code at the start of the MainPage handler in the example fails.

class MainPage(RequestHandler):

  def get(self):
    # Build a new oauth handler and display authorization url to user.
    auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
    print auth.get_authorization_url() # EXCEPTION 401 Unauthorized

Any help would be appreciated.

1

1 Answers

0
votes

Found the solution

Other than updating the callback in tweepy with the callback URL, also update in app section in dev.twitter.com also.

so, you have to give the correct callback URL while

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET, CALLBACK)

and also in the twitter app section.