问题描述
请指教:)
当我使用这个脚本时:
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 %s %s %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)
那我该怎么办?
推荐答案
您的示例似乎来自 这里.您正在使用 Tweepy,这是一个用于访问 Twitter API 的 Python 库.
Your example appears to be from here. And you are using Tweepy, a Python library for accessing the Twitter API.
来自 Github,这里是一个Stream() 对象(假设你有最新版本的 Tweepy,请仔细检查!),
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
因为您似乎传递了适当数量的参数,所以看起来 CustomStreamListener() 没有被初始化,因此没有被传递给 Stream() 类作为参数.查看是否可以在将 CustomStreamListener() 作为参数传递给 Stream() 之前对其进行初始化.
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().
这篇关于TypeError: __init__() 至少需要 4 个非关键字参数(给定 3 个)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)