来自Python twitter工具的授权错误

时间:2015-07-31 09:19:09

标签: python-3.x twitter authorization twitter-oauth

尝试使用Python Twitter工具搜索包含主题标签的tweeets。 (在带有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"))

但我总是收到授权错误。

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.'}]}

我已经尝试检查我的时间(并更改时区)。 我已经尝试将回调网址放入应用设置并重新生成密钥。

任何帮助表示赞赏

由于

1 个答案:

答案 0 :(得分:1)

无法解决这个问题,所以转移到了一个有效的文件库!