【问题标题】:AttributeError: module 'tweepy.streaming' has no attribute 'StreamListener'AttributeError:模块“tweepy.streaming”没有属性“StreamListener”
【发布时间】:2021-12-09 18:51:36
【问题描述】:

我正在使用 Tweepy 监控用户并且我正在使用流元素,但是我收到了这个错误

AttributeError: module 'tweepy.streaming' has no attribute 'StreamListener'

这是导入:

import tweepy
from tweepy import streaming

我也尝试过导入:

from tweepy.streaming import Stream

这是我的代码:

class MyStreamListener(tweepy.streaming.StreamListener):
    

    def on_status(self, status):
        webhook.send(status.text)
        # SMS.send(status.text)
        print(status.text)

    def on_error(self, status_code):
        if status_code == 420:
            #returning False in on_error disconnects the stream
            return False

myStreamListener = MyStreamListener()
myStream = tweepy.Stream(auth = api.auth, listener=myStreamListener)
# edit with the twitter IDs as needed
myStream.filter(follow=["twitter id"],is_async=True)

【问题讨论】:

标签: python twitter tweepy


【解决方案1】:

Tweepy v4.0.0 合并 StreamListenerStream
我建议您将代码更新为子类 Stream
或者,您可以降级到 v3.10.0。

【讨论】:

    猜你喜欢
    • 2021-11-23
    • 2018-04-14
    • 2019-02-18
    • 1970-01-01
    • 2020-01-01
    • 2019-07-20
    • 2021-11-05
    • 2021-11-04
    相关资源
    最近更新 更多