Marco
Marco

Reputation: 11

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

I'm using Tweepy to monitor a user and I'm using the stream element, but I got this error

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

This are the import:

import tweepy
from tweepy import streaming

I also tried importing:

from tweepy.streaming import Stream

This is my code:

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)

Upvotes: 1

Views: 1150

Answers (2)

Davidelvis
Davidelvis

Reputation: 151

Yes, StreamListener was merged into Stream in Tweepy v4.0.0, almost two years ago, and Stream was removed in Tweepy v4.14.0, as streaming with Twitter API v1.1 has been deprecated.

tweepy.Stream was a class, not an attribute, and tweepy.stream never existed.

If you want to use streaming, you'll have to use Twitter API v2 with StreamingClient and Pro or Enterprise access.

Upvotes: 0

Harmon758
Harmon758

Reputation: 5157

Tweepy v4.0.0 merged StreamListener into Stream.
I recommend updating your code to subclass Stream instead.
Alternatively, you can downgrade to v3.10.0.

Upvotes: 1

Related Questions