Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)?

like image 797
John Avatar asked Nov 13 '22 07:11

John


1 Answers

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.

like image 125
alecxe Avatar answered Nov 14 '22 23:11

alecxe