holmeswatson
holmeswatson

Reputation: 995

Authorization error from Python twitter tools

Trying to use Python Twitter Tools to search for the tweeets containing a hashtag. (On a raspberry Pi with python3).

from twitter import *
token = "token"
token_key = "token_key"
con_secret = "con_secret"
con_secret_key = "con_secret_key"

t = Twitter(
    auth=OAuth(token, token_key, con_secret, con_secret_key))

print(t.search.tweets(q="#test"))

But I always get a Authorization error.

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/twitter/api.py", line 319, in _handle_response
    handle = urllib_request.urlopen(req, **kwargs)
  File "/usr/lib/python3.4/urllib/request.py", line 153, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.4/urllib/request.py", line 461, in open
    response = meth(req, response)
  File "/usr/lib/python3.4/urllib/request.py", line 571, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python3.4/urllib/request.py", line 499, in error
    return self._call_chain(*args)
  File "/usr/lib/python3.4/urllib/request.py", line 433, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.4/urllib/request.py", line 579, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 401: Authorization Required

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "twitter-test.py", line 10, in <module>
    print(t.search.tweets(q="#test"))
  File "/usr/local/lib/python3.4/dist-packages/twitter/api.py", line 312, in __call__
    return self._handle_response(req, uri, arg_data, _timeout)
  File "/usr/local/lib/python3.4/dist-packages/twitter/api.py", line 345, in _handle_response
    raise TwitterHTTPError(e, uri, self.format, arg_data)
twitter.api.TwitterHTTPError: Twitter sent status 401 for URL: 1.1/search/tweets.json using parameters: (oauth_consumer_key=**key**&oauth_nonce=**nonce**&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1438333973&oauth_token=**token**&oauth_version=1.0&q=%23test&oauth_signature=**signature**)
details: {'errors': [{'code': 32, 'message': 'Could not authenticate you.'}]}

I have tried checking my time (and changing the timezone). I have tried putting in a callback URL into the app settings and regenerating the keys.

Any help appreciated

Thanks

Upvotes: 2

Views: 242

Answers (1)

holmeswatson
holmeswatson

Reputation: 995

Couldn't fix this so moved to tweepy library which works a treat!

Upvotes: 1

Related Questions