$ py twitterDump2.py
Traceback (most recent call last):
File "twitterDump2.py", line 30, in <module>
stream=tweepy.Stream(username,password,listener)
TypeError: __init__() takes exactly 3 arguments (4 given)
My code:
username="abc"
password="abc"
listener = StreamWatcherListener()
stream=tweepy开发者_开发问答.Stream(username,password,listener)
The first argument to __init__ is usually self so it is expecting you to pass only two arguments.
Surprising the tweepy.streaming.py code suggests:
class Stream(object):
host = 'stream.twitter.com'
def __init__(self, auth, listener, **options):
self.auth = auth
self.listener = listener
The auth is created this way:
auth = tweepy.BasicAuthHandler(username, password)
Your code should be something like this
username="abc"
password="abc"
listener = StreamWatcherListener()
auth = tweepy.BasicAuthHandler(username, password)
stream=tweepy.Stream(auth,listener)
See the code at : http://github.com/joshthecoder/tweepy/blob/master/tweepy/streaming.py
pyfunc has given the reasons why this is not working.
To see what arguments, type:
help(tweepy.Stream)
This will give you what arguments the Stream class requires.
This is for your reference:
def __init__(self, auth, listener, **options)
options
takes a dictionary that delivers keywords arguments with the ** operator.
精彩评论