TypeError: __init__() takes at least 4 non-keyword arguments (3 given)

前端 未结 3 1472
天涯浪人
天涯浪人 2021-01-16 01:58

Advice please :)

When I use this script:

class CustomStreamListener(tweepy.StreamListener):

    def on_status(self, status):

        # We\'ll simpl         


        
相关标签:
3条回答
  • 2021-01-16 02:37

    Your example appears to be from here. And you are using Tweepy, a Python library for accessing the Twitter API.

    From Github, here is the definition of a Stream() object (assuming you have the latest version of Tweepy, please double check!),

    def __init__(self, auth, listener, **options):
            self.auth = auth
            self.listener = listener
            self.running = False
            self.timeout = options.get("timeout", 300.0)
            self.retry_count = options.get("retry_count")
            self.retry_time = options.get("retry_time", 10.0)
            self.snooze_time = options.get("snooze_time",  5.0)
            self.buffer_size = options.get("buffer_size",  1500)
            if options.get("secure"):
                self.scheme = "https"
            else:
                self.scheme = "http"
    
            self.api = API()
            self.headers = options.get("headers") or {}
            self.parameters = None
            self.body = None
    

    Because you seemed to have passed in the appropriate number of arguments, it looks like CustomStreamListener() isn't being initialized, and therefore isn't being passed to the Stream() class as an argument. See if you can initialize a CustomStreamListener() prior to being passed as an argument to Stream().

    0 讨论(0)
  • 2021-01-16 02:37

    The main reason of this issue is using the older version of tweepy. I was using tweepy 1.7.1 and having the same error before I updated tweepy 1.8. Right after that, the issue was solved. I think the 4 voted answer should be accepted answer to clarify the solution.

    0 讨论(0)
  • 2021-01-16 03:03

    __init__ is the constructor of a class, in this case Stream. The error means you have provided a wrong number of arguments to the constructor call.

    0 讨论(0)
提交回复
热议问题