Hi I have been trying to remove non existing twitter users from a list. The reason I want to do this is because overtime I run my code some of the twitter users no longer exist and I get this error
kages/tweepy-3.6.0-py3.6.egg/tweepy/binder.py", line 234, in execute
tweepy.error.TweepError: [{'code': 34, 'message': 'Sorry, that page does not exist.'}]
I can't finish collecting my data because this error keeps stopping the code form running so I have been manually going one by one through my list and finding the twitter accounts that don't exist on twitter which is very inefficient. So I have been trying to use a try except block to override this code, as in remove the usernames that no longer exist and keep running my program but everything I have attempted doesn't work. This is my try except block without tweepy (just regular code) which works.
l=["b",23,"c",6,5]
print(l)
for i in range(0,10):
try:
for a in l:
print("a=",int(a))
except ValueError:
l.remove(a)
print(l)
continue
else:
print(l)
continue
Now I tried to implement this into my twitter list
pro_trump=['TruthSerum888','karlyherron', 'R41nB14ck', 'RedApplePol', 'MKhaoS_86']
for i in range(0,3):
try:
for screen_name in pro_trump:
user_followers=api.friends_ids(id=screen_name)# this returns the interger value of the user id a sepcifc user is following
except tweepy.error.TweepError:
print("screen_name that failed=", screen_name)
pro_trump.remove(screen_name)
print(pro_trump)
continue
else:# if no error
print(pro_trump)
continue
But it doesn't work. it just goes through the pro_trump list removing each username through the list regardless of if the tweeter account still exists or not. Can someone help me implement what I actually wish my code would do?