从 tweepy 异常实例中获取错误代码 [英] Get the error code from tweepy exception instance
本文介绍了从 tweepy 异常实例中获取错误代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 Python 新手,我正在尝试使用一个库.它引发了一个异常,我试图确定是哪一个.这就是我正在尝试的:
I'm new to python and I'm trying to use a library. It raises an exception, and I am trying to identify which one. This is what I am trying:
except tweepy.TweepError as e:
print e
print type(e)
print e.__dict__
print e.reason
print type(e.reason)
这是我得到的:
[{u'message': u'Sorry, that page does not exist', u'code': 34}]
<class 'tweepy.error.TweepError'>
{'reason': u"[{u'message': u'Sorry, that page does not exist', u'code': 34}]", 'response': <httplib.HTTPResponse instance at 0x00000000029CEAC8>}
[{u'message': u'Sorry, that page does not exist', u'code': 34}]
<type 'unicode'>
我正在尝试使用该代码.我试过 e.reason.code 没有成功,我不知道该尝试什么.
Im trying to get to that code. I have tried e.reason.code with no success and I have no idea what to try.
推荐答案
这个怎么样?
except tweepy.TweepError as e:
print e.message[0]['code'] # prints 34
print e.args[0][0]['code'] # prints 34
这篇关于从 tweepy 异常实例中获取错误代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文