4
votes

I'm trying to post a tweet using Twython from Django-powered site. However, the 'twitter.updateStatus(status=tweet_text)' line results in the following error:

TwythonError: u'Unauthorized: Authentication credentials were missing or incorrect. -- Invalid / expired Token'

I do have requests version 0.13.9, so this shouldn't be an issue:

>>>import pkg_resources
>>>pkg_resources.get_distribution("requests").version
'0.13.9'
>>>pkg_resources.get_distribution("twython").version
'2.3.4'

Any idea how to fix this? Thanks in advance!

Here's the python method itself:

def tweet_link(request, tweet_text):
    try:
        c = RequestContext(request)
        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']
        )
        twitter.updateStatus(status=tweet_text)
    except Exception, e:
        print traceback.print_exc()
    return HttpResponse('')
1

1 Answers

2
votes

I'm the author of Twython.

This bug was occurring due to an issue with a dependency we have (Requests), which has been fixed as of Requests v0.13.9. It should be fine now; do feel free to contact me if not.