我写了这个剧本:
import tweetstream
import pymongo
connection = pymongo.Connection("mongodb://localhost:27017")
db = connection.socialdata
words = ["social media", "innovation", "cloud computing"]
with tweetstream.FilterStream('username', 'password', track=words) as stream:
for tweet in stream:
db.tweets.save(tweet)但在执行时,我会收到以下错误,请告诉我如何删除此错误:
Traceback (most recent call last):
File "tweet.py", line 9, in <module>
with tweetstream.FilterStream(username, password, track=words) as stream:
TypeError: __init__() takes at least 5 arguments (4 given)</module>提前谢谢。
发布于 2013-10-15 12:34:04
我想知道tweetstream最初是如何工作的,因为我只知道一些时候基本的用户名/密码访问是已弃用。现在Twitter只允许OAuth访问。
回到您的问题,您的FileStream调用是完全有效的。看看FileStream类实现,您就会理解其中的原因。
下面是来自FilterStream类的几行代码,它是可用的这里
def __init__(self, username, password, follow=None, locations=None,
track=None, catchup=None, raw=False, timeout=None, url=None):
self._follow = follow
self._locations = locations
self._track = track
# remove follow, locations, track
BaseStream.__init__(self, username, password,
raw=raw, timeout=timeout, url=url)所以,tweetstream.FilterStream("username", "password", track=words)应该能工作。因为正如您所看到的,__init__只有3个强制参数。(self,用户名,密码)。
其他的都是可选的。请注意,此代码来自于我认为上一版本发布的tweetstream 1.1.1。
但是,正如您在错误中所说的,FilterStream构造函数在tweetstream中至少需要5个参数。
这文档给出了一个您想要做的事情的示例。
就像它说的,尝试使用这个初始化,
with tweetstream.FilterStream("username", "password", track=words,
follow=people, locations=locations) as stream据消息来源称,
https://stackoverflow.com/questions/19381039
复制相似问题