我正在尝试使用tweepy从Streaming API流推文,并打印已流化的每个推文的文本。我收到以下错误:
TypeError:on_exception()缺少1个必需的位置参数: “例外”
我为什么要得到它,如何解决?
我遇到了类似的错误,它说将请求库降级到2.7。不用说,它没有用。
class Authenticator():
def authenticate_and_get_API_object(self):
auth = tweepy.OAuthHandler(consumerkey,consumersecret)
auth.set_access_token(accesstoken,accesstokensecret)
api = tweepy.API(auth)
return api
class MyStreamListener(tweepy.StreamListener):
def on_status(self,status):
print(status.text)
def on_error(self,status_code):
if status_code==420:
return false
if __name__ == "__main__":
my_streamer = MyStreamListener()
the_api = Authenticator().authenticate_and_get_API_object()
myStream = tweepy.Stream(auth = the_api.auth, listener = MyStreamListener)
myStream.filter(track=['python'])
任何帮助将不胜感激
错误回溯:
Traceback (most recent call last):
File "streamdemtweets.py", line 24, in <module>
myStream.filter(track=['python'])
File "/home/ansuman/.local/lib/python3.7/site-packages/tweepy/streaming.py", line 453, in filter
self._start(is_async)
File "/home/ansuman/.local/lib/python3.7/site-packages/tweepy/streaming.py", line 368, in _start
self._run()
File "/home/ansuman/.local/lib/python3.7/site-packages/tweepy/streaming.py", line 299, in _run
self.listener.on_exception(exc_info[1])
TypeError: on_exception() missing 1 required positional argument: 'exception'
答案 0 :(得分:1)
我解决了实例化时在MyStreamListener中添加()的问题:
myStream = tweepy.Stream(auth = the_api.auth, listener = MyStreamListener())