I am using python-twitter with the Twitter Streaming API to try and collect tweets from the UK which are about a particular topic. The loop I'm using is:
while True:
try:
for item in api.GetStreamFilter(locations = UK_BB, stall_warnings = True):
tweet = parse_tweet(item)
if relevant(tweet):
save_tweet(tweet)
except Exception as err:
logging.exception("Error at %s:", datetime.datetime.now().strftime("%A, %d. %B %Y %I:%M%p"))
This process works fine for about five minutes, saving relevant tweets. However after about five minutes, every time, data stops coming from the API. I don't receive any exceptions or any unusual messages from the stream. I don't have more than one connection open to the stream. The API credentials seem to be fine and there's nothing wrong with my connection. Restarting the connection will make it work for another five minutes, but then the problem will kick in again.
Does anyone have any idea what might be going wrong here?