0

I'm trying to loop through a list of tweet ID's but if I encounter one that no longer exists I receive a 404 error and the script just stops. I've tried something like this:

try:
    twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
    twt=twitter.show_status(<twitterID>)
except Exception as e:
    pass

but that still stops the script. I'd like to be able to log (or print) the ID and continue the script.

Thanks,B

  • 3
    How about posting your code, instead of "something like" your code? – kindall Sep 23 '13 at 20:11
  • You could try calling the error you're receiving explicitly (though you would fail on other exceptions if you didn't also call them). Agree with kindall however, actual code and the traceback would be helpful in resolving your issue. – Benjooster Sep 23 '13 at 20:31

1 Answers1

0

Change this:

from twython import Twython

To this:

from twython import Twython, exceptions

Then use the error you see when the code fails with something like this:

try:
    twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
    foo = twitter.verify_credentials()
except(SomeError):
    pass

Replace the "SomeError" with whatever one twython dumped you to.

If it's anything else that's at fault then you need to follow the advice of others here and post your code along with the actual error message.

Ben
  • 3,981
  • 2
  • 25
  • 34