Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

type error 'class' object not callable

Tags:

python

tweepy

I have a class MyStreamListener that I'm trying to call from a different file, but I get the type error 'MyStreamListener' not callable. From what I've read when referencing user made classes, it could be because I'm trying to access a reserved keyword in python, but I've already tried changing the name of the class. Is there anything else I'm doing wrong?

functionality.py

from authenticate import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET
from twitter_stream import MyStreamListener

def oauth_authenticate():
        auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
        auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
        api = tweepy.API(auth)

        return api

def streaming():
        api = oauth_authenticate()
        streamListener = MyStreamListener()

        stream = tweepy.Stream(auth=api.auth, listener=streamListener())

if __name__ == '__main__':
        print "wanting to stream"
        streaming()
        print "EXITING"

twitter_stream.py

import tweepy

class MyStreamListener(tweepy.StreamListener):

        def on_status(self, status):
                print(status.text)
like image 726
Rafa Avatar asked Dec 21 '15 21:12

Rafa


1 Answers

In the line:

stream = tweepy.Stream(auth = api.auth, listener = streamListener())

you are trying to call streamListener since you've got the parens there. Instead, just pass the object itself, i.e.:

stream = tweepy.Stream(auth=api.auth, listener=streamListener)
like image 61
Randy Avatar answered Oct 22 '22 10:10

Randy