Twitter authentication error on Twython 2.3.4 with error: 401, Failed to verify the signature and oauth token

I just upgraded to Twython 2.3.4, but now my Twitter authorizer is stopping. It does not work on the line auth_props = twitter.get_authentication_tokens (). Any idea what went wrong? Thanks in advance!

The python code for performing Twitter authorization using Twython is below:

def begin_auth(request): twitter = Twython( twitter_token = TWITTER_KEY, twitter_secret = TWITTER_SECRET, callback_url = request.build_absolute_uri(reverse('portnoy.views.thanks')) ) # Request an authorization url to send the user to... auth_props = twitter.get_authentication_tokens() 

I have the following error in the line above: TwythonAuthError: "It seems that something could not be verified using the OAuth utility. Error: 401, Message: failed to verify oauth signature and token"

  # Then send them over there, durh. request.session['request_token'] = auth_props return HttpResponseRedirect(auth_props['auth_url']) def thanks(request, redirect_url='/'): c = RequestContext(request) # for permanent ones and store them... twitter = Twython( twitter_token = TWITTER_KEY, twitter_secret = TWITTER_SECRET, oauth_token = request.session['request_token']['oauth_token'], oauth_token_secret = request.session['request_token']['oauth_token_secret'] ) # Retrieve the tokens we want... authorized_tokens = twitter.get_authorized_tokens() request.session['request_tokens'] = authorized_tokens debug('thanks', request.session['request_tokens']) user = User.objects.filter(username=authorized_tokens['screen_name']) if user.exists(): user = user[0] user.backend='django.contrib.auth.backends.ModelBackend' auth.login(request,user) else: return render_to_response('twitter_register.html', c) return HttpResponseRedirect(redirect_url) 
+4
source share
2 answers

I am the author of Twython.

What version of queries are you using under the hood? Recently, there was a problem where people were constantly confronted with various OAuth related errors due to upstream error. Curious if this is related to this ...

+2
source

I ran into the same problem myself. This does not seem to work if you are testing locally.

Here is what I did to fix this:

  • Edit the hosts file (on OSX, which is located at / private / etc / hosts). Add line: 127.0.0.1 myapp.com
  • Go to the "Twitter Settings" tab and go to the "Settings" tab. Set the callback url: http://myapp.com:8000/thanks

Make sure you set the port number and URL correctly. Hope this helps!

+1
source

All Articles