2015-12-21 62 views
3

我有一個類MyStreamListener,我試圖從不同的文件調用,但我得到了type error 'MyStreamListener' not callable。從引用用戶創建的類時讀到的內容可能是因爲我試圖訪問python中的保留關鍵字,但我已經嘗試更改類的名稱。還有什麼我做錯了嗎?類型錯誤'類'對象不可召喚

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) 
+0

我遇到了同樣的問題。官方Tweepy文檔包含相同的錯誤 –

回答

9

在行:

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

你想打電話streamListener因爲喲你在那裏找到了那些人。相反,只是通過對象本身,即:

stream = tweepy.Stream(auth=api.auth, listener=streamListener) 
相關問題