【发布时间】:2018-09-28 16:40:04
【问题描述】:
我目前正在使用 Tweepy 库,并且从几天前就启动了它。但是过了一会儿,我在收集的每条推文之间收到了以下消息:
HTTP 错误 429:请求过多
或者
服务不可用
我认为在处理这种事情时将函数wait_on_rate_limit设置为True,或者它没有考虑429错误?我刚刚在我的过滤器中请求了大约 10 个术语,最多每 5-10 秒返回大约 1 条推文。
我该如何处理这类问题?顺便说一句,有我的一段代码:
streamer = tweepy.Stream(auth=api.auth, listener=StreamListener(), timeout=3000000000)
streamer.filter(None,terms)
class StreamListener(tweepy.StreamListener):
status_wrapper = TextWrapper(width=60, initial_indent=' ', subsequent_indent=' ')
def on_status(self, status):
print ('{} {} - {}'.format(status.author.screen_name, status.created_at,status.text))
saveTweet(status)
def on_disconnect(self, notice):
print ("Disconnect: {}".format(notice))
return
def on_warning(self, notice):
print ("Warning: {}".format(notice))
return
def on_exception(self, exception):
print ("Exception: ".format(exception))
return
def on_error(self, status_code):
if (status_code == 403):
print("Limit probably reached")
else:
print("Error occured > {}".format(status_code))
return False
【问题讨论】:
-
我现在在收集的推文之间也有以下消息
Service not available
标签: python twitter tweepy http-status-code-429