tweepy/twitter api错误类型

Joh*_*ohn 5 python twitter tweepy

我正在使用tweepy制作推特应用程序.当用户发推文/更新个人资料等时,他们会收到一些错误.我想对错误进行分类并为用户提供更多信息.

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
Run Code Online (Sandbox Code Playgroud)

分类错误的唯一方法是e与字符串进行比较,例如,Account update failed: Description is too long (maximum is 160 characters)

ale*_*cxe 1

没错,现在只有这个办法了。仅定义了一个TweepError异常。它在整个应用程序中以不同的文本出现。

这是 github 上的相关开放问题。所以未来有可能会得到改进。