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

前端 未结 3 1514
天涯浪人
天涯浪人 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().

提交回复
热议问题