类型错误:__init__() 至少需要 4 个非关键字参数(给定 3 个)

0 投票
1 回答
1613 浏览
提问于 2025-04-16 22:38

可能是重复的问题:
类型错误:init() 至少需要 4 个位置参数,但只给了 3 个

当我使用这个脚本时:

import sys, tweepy, webbrowser

Q = sys.argv[1:] 

class CustomStreamListener(tweepy.StreamListener):

    def on_status(self, status):       
        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 
streaming_api = tweepy.streaming.Stream(auth, CustomStreamListener(), timeout=60)

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)

我该怎么办?

1 个回答

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

在这一行,你需要把 auth 替换成 usernamepassword,分别使用这两个,或者更新到最新版本的 tweepy。

撰写回答