Sevenless
Sevenless

Reputation: 2835

Twython OAuth1 issues, 401 error using example code

I'm trying to setup a stream using the latest version of Twython with Python 2.7.3. I'm trying to reproduce the example in the streaming docs which depend on the OAuth1 docs. Using the following code yields 401 errors until I kill execution:

from twython import Twython
from twython import TwythonStreamer

class MyStreamer(TwythonStreamer):
    def on_success(self, data):
        if 'text' in data:
            print['text'].encode('utf-8')

    def on_error(self, status_code, data):
        print status_code


APP_KEY    = 'mupAeFE44nOU5IlCo4AO0g' # Consumer key in twitter app OAuth settings
APP_SECRET = 'NOTMYSECRET0zo1WbMAeSIzZgh1Hsj9CrlShonA'  # Consumer secret in OAuth settings

twitter = Twython(APP_KEY,APP_SECRET)
auth = twitter.get_authentication_tokens()

OAUTH_TOKEN        = auth['oauth_token']
OAUTH_TOKEN_SECRET = auth['oauth_token_secret']

stream = MyStreamer(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
stream.statuses.filter(track = 'twitter')

The values of 'OAUTH_TOKEN' and 'OAUTH_TOKEN_SECRET' end up set to unicode strings. I've set 'APP_KEY' and 'APP_SECRET' as above or as unicode strings both with the same results.

Following the advice in this reported issue I updated both requests and requests-oauthlib without luck.

I don't believe I'm having firewall issues. At this point, I've tried this code on three different boxes all in different locales all with the same results.

Not sure how to proceed at this point. All help appreciated.

Upvotes: 3

Views: 1304

Answers (1)

Jonatas CD
Jonatas CD

Reputation: 908

What happens when you run something like the code below?

from twython import Twython

CONSUMER_KEY = "****"
CONSUMER_SECRET = "****"

OAUTH_TOKEN = "****"
OAUTH_TOKEN_SECRET = "******"

twitter = Twython(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)

import json
print(json.dumps(twitter.get_user_timeline(screen_name='jonatascd')[0], indent=2))

I've openend an issue at github with a similar question, almost at the same time [1], because I'm with the same problem here (and I've tried in more than one scenario)


UPDATE: from the solution that came up in the issue [1] - run:

ntpd -q

that is because the system time was a little off. Well, for me worked.

[1] https://github.com/ryanmcgrath/twython/issues/237

Upvotes: 3

Related Questions