Tweepy.StreamListener()提供奇怪的输出

时间:2019-05-12 04:23:13

标签: python json tweepy

我正在尝试运行扭曲的Stream,并且一遍又一遍地得到这个奇怪的输出-'401'-无论我正在跟踪的str为何,甚至具有不同的StreamListener类/重写的on_status。

我最初尝试使用json.dump()将推文流写入txt文件,然后使用推文数据创建Pandas Dataframe,但是我又回到了简单的结构,只需打印推文即可。现在/仍然一遍又一遍地获得此401输出。还看到了AppAuthHandler和OAuthHandler方法在各种代码中调用键,因此尝试了两者-结果相同。

auth = tweepy.OAuthHandler(auth_key, secret_key)
api = tweepy.API(auth)

class StreamListener(tweepy.StreamListener):

  def on_status(self,status):
    '''This is what to modify to filter, or edit, or add tweets to DF column !'''
    print(status.text)

  def on_error(self,status_code):
    if status_code == 420:
        return False


s = StreamListener()

stream = tweepy.Stream(auth,s)

stream.filter(track=['$AMZN','$AAPL','$FB','$MSFT','$TSLA'],async=True)

预期的tweet数据,但输出为:

401 401 401 401 401 401 401 401 401 401 401

0 个答案:

没有答案
相关问题