Python 使用流式API tweepy避免错误420s
我制作了一个python脚本,它使用tweepy流媒体模块将提及的内容流式传输到twitter帐户,并根据状态文本携带一些函数 我想让它一直流到有人提到,下一步停止流,根据状态文本执行一些功能,然后再次开始流 这是我的代码:Python 使用流式API tweepy避免错误420s,python,twitter,twitter-streaming-api,Python,Twitter,Twitter Streaming Api,我制作了一个python脚本,它使用tweepy流媒体模块将提及的内容流式传输到twitter帐户,并根据状态文本携带一些函数 我想让它一直流到有人提到,下一步停止流,根据状态文本执行一些功能,然后再次开始流 这是我的代码: class StdOutListener(tweepy.StreamListener): def on_data(self, data): tweet = json.loads(data.strip()) global d
class StdOutListener(tweepy.StreamListener):
def on_data(self, data):
tweet = json.loads(data.strip())
global d
d=tweet
return False #stops streaming after a tweet is fed to it
def on_error(self, status_code):
print(status_code)
time.sleep(120)
return F # To continue listening
def on_timeout(self)
time.sleep(120)
return True # To continue listening
while True:
d={}
listener = StdOutListener()
stream = tweepy.Stream(twitter_auth(tokens), listener)
stream.filter(track=['@xxx'])
stream.disconnect()
doSomething(d)
但它只适用于一个循环,之后会显示420个(超过速率限制)错误,即使我只接收一条tweet(每个流,如果我没有错的话)
谁能解释一下我哪里做错了?还有,我们什么时候应该在tweepy stream listener中使用异步模式?您所做的任何事情都是错误的,只是tweepy所基于的twitter api对下载有限制