Tweepy/Twitter API错误类型

5

我正在使用tweepy制作Twitter应用程序。当用户发推文/更新个人资料等时,他们会遇到一些错误。我希望对这些错误进行分类,并向用户提供更多信息。

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

分类错误的唯一方法是将e与字符串进行比较,例如:帐户更新失败:说明太长(最多为160个字符)吗?

1个回答

1

没错,现在这是唯一的方法。应用程序中只定义了一个TweepError异常,并且在不同的文本中引发。

以下是github上相关的问题。因此,未来有可能会得到改进。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接