John
John

Reputation: 4028

tweepy/ twitter api error type

I am using tweepy to make a twitter application. When users tweet/update profile, etc, they will get some errors. I want to classify error and give user more information.

try:
    tweet/update profile/ follow....

except tweepy.TweepError, e:

    if tweepy.TweepError is "Account update failed: Description is too long (maximum is 160 characters)"
        Do something
    if tweepy.TweepError is "Failed to send request: Invalid request URL: http://api.twitter.com/1/account/update_profile.json?location=%E5%85%B5%E5%BA%A"
        Do something
    if tweepy.TweepError is "[{u'message': u'Over capacity', u'code': 130}]" 
        Do something

Is the only way to classify error is to compare e with string, for example, Account update failed: Description is too long (maximum is 160 characters)?

Upvotes: 5

Views: 2525

Answers (1)

alecxe
alecxe

Reputation: 473763

Right, it is the only way now. There is only one TweepError exception defined. It's raised throughout the app with different text.

Here's the relevant open issue on github. So there is a chance that it'll be improved in the future.

Upvotes: 1

Related Questions