【问题标题】:python tweepy streaming command line result 401python tweepy流命令行结果401
【发布时间】:2015-10-17 20:59:30
【问题描述】:

我在python命令行中写了以下代码。

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 实时流输出?

【问题讨论】:

  • 401 未经授权。

标签: python python-3.x output tweepy


【解决方案1】:

此错误来自 twitter 的Error Codes & Responses 列表。 401 表示:

请求无效或无法以其他方式提供服务。一个陪伴 错误信息将进一步解释。在 API v1.1 中,请求没有 身份验证被视为无效并会产生此响应。

本质上是因为您的密钥或令牌之一不正确,只需仔细检查它们就可以了。

从python它来自这行代码:

def on_error(self, status):
    print(status)

您从 twitter 获得的 status 是 401,因此您看到 401 正在打印。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-23
    • 1970-01-01
    • 2018-05-30
    • 2017-09-17
    • 2015-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多