toshiro92 toshiro92 - 17 days ago 10
Python Question

Tweepy does not handle 429 HTTP error (Too many Requests)

I am currently using Tweepy library, and I launched it since several days. However after a while, I received the following message between each tweet collected:


HTTP Error 429: Too Many Requests


Or


Service not available


I thought set as True the function
wait_on_rate_limit
while handle this kind of thing, or maybe it does not take account of 429 error ? I just requested about 10 terms in my filter, which returns around 1 tweet per 5-10 sec maximum.

How can I handle this kind of issue ? There is my piece of code btw:

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

Answer

Hi!

For those who have the same issue, just upgrade Tweepy ! I raised an issue on the Github's Tweepy project, and it has been solved. Please see issue #791 for more information