views:

32

answers:

2
$ 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)
+2  A: 

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
What arguments?
TIMEX
Are they string/dict?
TIMEX
Thanks!! But, in the future, how do I know what argument types it accepts?
TIMEX
@TIMEX: See my edited answer. The auth is created using username and password and then the same is passed on to tweepy.Stream
pyfunc
@TIMEX: PulFiction answers your question on how to find things. Use help() function and also the code is easy to read. just do that. Nothing to shy away from :)
pyfunc
+2  A: 

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.

sukhbir
@PulpFiction: His issues was passing the auth incorrectly
pyfunc
Aah! I was replying to his question as to how to see arguments of a Python method :)
sukhbir