python tweepy流式命令行结果401
问题描述:
我在python命令行中编写了下面的代码。python tweepy流式命令行结果401
from __future__ import absolute_import, print_function
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
consumer_key="***"
consumer_secret="***"
access_token="***"
access_token_secret="***"
class StdOutListener(StreamListener):
""" A listener handles tweets are the received from the stream.
This is a basic listener that just prints received tweets to stdout.
"""
def on_data(self, data):
print(data)
return True
def on_error(self, status):
print(status)
if __name__ == '__main__':
l = StdOutListener()
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
stream = Stream(auth, l)
stream.filter(track=['basketball'])
然而,结果总是只是'401'。没有任何错误消息。这意味着什么?我需要做些什么来获得twitter实时流输出?
答
此错误来自推特的Error Codes & Responses列表。 401表示:
该请求无效或无法以其他方式提供。伴随的 错误信息将进一步解释。在API v1.1中,没有 身份验证的请求被认为是无效的,并会产生此响应。
实际上,这是因为你的一个密钥或令牌不正确,只需再次检查它们,你应该很好。
从蟒蛇它是从下面这行代码来:
def on_error(self, status):
print(status)
的status
你从Twitter得到的是401,所以你看到401正在打印。
401未经授权。 –