Python TypeError:\uuuu init\uuuuu()至少接受4个非关键字参数(给定3个)

Python TypeError:\uuuu init\uuuuu()至少接受4个非关键字参数(给定3个),python,api,streaming,arguments,Python,Api,Streaming,Arguments,请注意:) 当我使用此脚本时: class CustomStreamListener(tweepy.StreamListener): def on_status(self, status): # We'll simply print some values in a tab-delimited format # suitable for capturing to a flat file but you could opt # stor

请注意:)

当我使用此脚本时:

class CustomStreamListener(tweepy.StreamListener):

    def on_status(self, status):

        # We'll simply print some values in a tab-delimited format
        # suitable for capturing to a flat file but you could opt 
        # store them elsewhere, retweet select statuses, etc.



        try:
            print "%s\t%s\t%s\t%s" % (status.text, 
                                      status.author.screen_name, 
                                      status.created_at, 
                                      status.source,)
        except Exception, e:
            print >> sys.stderr, 'Encountered Exception:', e
            pass

    def on_error(self, status_code):
        print >> sys.stderr, 'Encountered error with status code:', status_code
        return True # Don't kill the stream

    def on_timeout(self):
        print >> sys.stderr, 'Timeout...'
        return True # Don't kill the stream

# Create a streaming API and set a timeout value of 60 seconds.

streaming_api = tweepy.streaming.Stream(auth, CustomStreamListener(), timeout=60)

# Optionally filter the statuses you want to track by providing a list
# of users to "follow".

print >> sys.stderr, 'Filtering the public timeline for "%s"' % (' '.join(sys.argv[1:]),)

streaming_api.filter(follow=None, track=Q)
出现了如下错误:

Traceback (most recent call last):
  File "C:/Python26/test.py", line 65, in <module>
    streaming_api = tweepy.streaming.Stream(auth, CustomStreamListener(), timeout=60)
TypeError: __init__() takes at least 4 non-keyword arguments (3 given)
回溯(最近一次呼叫最后一次):
文件“C:/Python26/test.py”,第65行,在
streaming_api=tweepy.streaming.Stream(auth,CustomStreamListener(),超时=60)
TypeError:\uuuu init\uuuuu()至少接受4个非关键字参数(给定3个)

那么我该怎么办呢?

\uuuu init\uuuu
是类的构造函数,在本例中是
。该错误意味着您为构造函数调用提供了错误数量的参数

\uuuu init\uuuu
是类的构造函数,在本例中为
。该错误意味着您为构造函数调用提供了错误数量的参数

您的示例似乎来自。您正在使用一个Python库来访问Twitter API

来自Github的是
Stream()
对象的定义(假设您拥有最新版本的Tweepy,请仔细检查!)


因为您似乎传入了适当数量的参数,所以它看起来好像没有初始化
CustomStreamListener()
,因此没有作为参数传递给
Stream()
类。查看是否可以在作为参数传递给
Stream()
之前初始化
CustomStreamListener()

您的示例似乎来自。您正在使用一个Python库来访问Twitter API

来自Github的是
Stream()
对象的定义(假设您拥有最新版本的Tweepy,请仔细检查!)


因为您似乎传入了适当数量的参数,所以它看起来好像没有初始化
CustomStreamListener()
,因此没有作为参数传递给
Stream()
类。查看是否可以在作为参数传递给
Stream()
之前初始化
CustomStreamListener()

此问题的主要原因是使用较旧版本的tweepy。我使用的是tweepy 1.7.1,在更新tweepy 1.8之前出现了相同的错误。紧接着,问题就解决了。我认为4票的答案应该被接受,以澄清解决方案。

这个问题的主要原因是使用旧版本的tweepy。我使用的是tweepy 1.7.1,在更新tweepy 1.8之前出现了相同的错误。紧接着,问题就解决了。我认为4票的答案应该被接受,以澄清解决方案。

您使用的是什么版本的Tweepy?它看起来像是
tweepy.streaming.Stream
在中从接受4个参数更改为3个参数。您使用的是什么版本的tweepy?它看起来像是
tweepy.streaming.Stream
在中从接受4个参数更改为3个参数。
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