Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"AttributeError: module 'tweepy' has no attribute 'StreamListener'" with Python 3.9

class MyStreamListener(tweepy.StreamListener):
    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

I use Python 3.9 and installed Tweepy via pip. I get the AttributeError on the class line. My import is just import tweepy. Authentication gets correctly handled. In the streaming.py file, I have the class Stream. But using this class ends in that. There is for example no status.text, even if there is the on_status function. I am a little bit confused.

like image 711
Nayjer Avatar asked Jul 13 '26 03:07

Nayjer


1 Answers

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.

like image 55
Harmon758 Avatar answered Jul 15 '26 16:07

Harmon758



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!