Python &引用;属性错误:';MyStreamListener';对象没有属性';api&x27&引用;二次误差
我有一个python程序,它在twitter上搜索一个单词,并统计所有提及该单词的次数。然而,我遇到了一个奇怪的问题,我在别处找不到答案。我得到一个“AttributeError:'MyStreamListener'对象没有属性'api'”错误。这是我第一次看到这个错误。有没有关于如何修复的建议 代码:Python &引用;属性错误:';MyStreamListener';对象没有属性';api&x27&引用;二次误差,python,tweepy,Python,Tweepy,我有一个python程序,它在twitter上搜索一个单词,并统计所有提及该单词的次数。然而,我遇到了一个奇怪的问题,我在别处找不到答案。我得到一个“AttributeError:'MyStreamListener'对象没有属性'api'”错误。这是我第一次看到这个错误。有没有关于如何修复的建议 代码: from tweepy import OAuthHandler import tweepy from tweepy import StreamListener from tweepy impo
from tweepy import OAuthHandler
import tweepy
from tweepy import StreamListener
from tweepy import Stream
import time
consumer_key = 'super secret consumer key'
consumer_secret = 'Please help Ive been stuck with this error for days'
access_token = 'Im so desperate'
access_secret = 'I suck at coding please help'
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
api = tweepy.API(auth)
print('')
class MyStreamListener(tweepy.StreamListener):
def __init__(self):
#initializes the counter
self.counter = 0
def on_status(self, status):
#prints status text. Also counts the mentions.
self.counter = self.counter + 1
print(status.text)
def on_error(self, status_code):
if status_code == 420:
print('420 error')
#Ends stream in case of rate limiting
return False
myStreamListener = MyStreamListener()
myStream = tweepy.Stream(auth = api.auth, listener = myStreamListener)
#Word
myStream.filter(track=['Warriors'])
在的开头添加super(MyStreamListener,self)。\uuuuu init\uuuu()
为我修复了它
def __init__(self):
super(MyStreamListener, self).__init__()
#initializes the counter
self.counter = 0
这也是我的问题