2013-04-09 84 views
5

我使用tweepy來製作twitter應用程序。 當用戶推特/更新配置文件等,他們會得到一些錯誤。我想分類錯誤併爲用戶提供更多信息。tweepy/twitter api錯誤類型

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與字符串,例如,Account update failed: Description is too long (maximum is 160 characters)

回答

1

對,現在是唯一的方法。定義的異常只有一個TweepError。它在整個應用程序中以不同的文字提出。

這是github上的相關開放issue。所以有可能在未來有所改善。