tweepy/twitter api 错误类型 [英] tweepy/ twitter api error type

查看:39
本文介绍了tweepy/twitter api 错误类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

推荐答案

对,这是现在唯一的办法.只定义了一个 TweepError 异常.它在整个应用中以不同的文字出现.

Right, it is the only way now. There is only one TweepError exception defined. It's raised throughout the app with different text.

这是 github 上的相关公开问题.所以以后有机会改进.

Here's the relevant open issue on github. So there is a chance that it'll be improved in the future.

这篇关于tweepy/twitter api 错误类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆