I'm writing a basic program using Python and Tweepy to take a list of Twitter screen names and pull down the corresponding user IDs. I've got the rate limiter implemented and the program works but things fall apart when it hits my exception handling. It's telling me that the screen name in X isn't present after it waits the 15 minutes. I need exception handling as Tweepy often runs into issues while running. What am I doing wrong here?
f = open('output2.txt', 'w')
while True:
for x in HandleList1:
try:
u = api.get_user(id = x)
print >> f, u.id
except tweepy.TweepError:
print "We just hit an error, waiting for 15min and then reconnecting..."
time.sleep(60*15)
u = api.get_user(id = x)
print >> f, u.id
except StopIteration:
print "Stopping the iteration and processing the results!"
break
f.close()