tweepy/ twitter api error type

南楼画角 提交于 2019-12-04 12:48:59

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/15895515/tweepy-twitter-api-error-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!