U. Watt
U. Watt

Reputation: 724

How to fix 'on_exception() missing 1 required positional argument: exception'?

I'm trying to use tweepy to stream tweets from the Streaming API and print the text of each tweet that has been streamed. I get the following error:

TypeError: on_exception() missing 1 required positional argument: 'exception'

Why am I getting this and how do I fix it?

I came across a similar error and it said to downgrade the requests library to 2.7. Needless to say, it didn't work.

    class Authenticator():
             def authenticate_and_get_API_object(self):
                     auth = tweepy.OAuthHandler(consumerkey,consumersecret)               
                auth.set_access_token(accesstoken,accesstokensecret)

                     api = tweepy.API(auth)
                     return api

    class MyStreamListener(tweepy.StreamListener):
            def on_status(self,status):
                    print(status.text)

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

    if __name__ == "__main__":

            my_streamer = MyStreamListener()
            the_api = Authenticator().authenticate_and_get_API_object()
            myStream = tweepy.Stream(auth = the_api.auth, listener = MyStreamListener)
            myStream.filter(track=['python'])

Any help would be appreciated

Error traceback:

Traceback (most recent call last):
  File "streamdemtweets.py", line 24, in <module>
    myStream.filter(track=['python'])
  File "/home/ansuman/.local/lib/python3.7/site-packages/tweepy/streaming.py", line 453, in filter
    self._start(is_async)
  File "/home/ansuman/.local/lib/python3.7/site-packages/tweepy/streaming.py", line 368, in _start
    self._run()
  File "/home/ansuman/.local/lib/python3.7/site-packages/tweepy/streaming.py", line 299, in _run
    self.listener.on_exception(exc_info[1])
TypeError: on_exception() missing 1 required positional argument: 'exception'

Upvotes: 1

Views: 2163

Answers (1)

Pedro Mu&#241;oz
Pedro Mu&#241;oz

Reputation: 700

I've solved it adding () to MyStreamListener when instantiating it:

myStream = tweepy.Stream(auth = the_api.auth, listener = MyStreamListener())

Upvotes: 3

Related Questions