“AttributeError: module ‘tweepy’ has no attribute ‘StreamListener'” with Python 3.9

We Are Going To Discuss About “AttributeError: module ‘tweepy’ has no attribute ‘StreamListener'” with Python 3.9. So lets Start this Python Article.

“AttributeError: module ‘tweepy’ has no attribute ‘StreamListener'” with Python 3.9

  1. How to solve “AttributeError: module 'tweepy' has no attribute 'StreamListener'” with Python 3.9

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

  2. “AttributeError: module 'tweepy' has no attribute 'StreamListener'” with Python 3.9

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

Solution 1

Tweepy v4.0.0 was released recently and it merged StreamListener into Stream.

I recommend updating your code to subclass Stream instead.
Alternatively, you can downgrade to v3.10.0.

Original Author Harmon758 Of This Content

Solution 2

As mentioned by @Harmon758, they merged StreamListener into Stream after version 4. Also you don`t need to create the api auth object separately. Here is the code:

from tweepy import Stream

class MyStreamListener(Stream):
    def on_status(self, status):
        print(status.text)  # prints every tweet received

    def on_error(self, status_code):
        if status_code == 420:  # end of monthly limit rate (500k)
            return False


stream = MyStreamListener('consumer_key',
                          'consumer_secret',
                          'access_token',
                          'access_token_secret')

stream.filter(track=["Python"], languages=["en"])

Original Author amir.rafieian Of This Content

Solution 3

If you look at the modules, the correct way to reference StreamListener is tweepy.streaming.StreamListener, not tweepy.StreamListener.

Original Author pigeonburger Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

ittutorial team

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment