【发布时间】:2013-06-14 00:15:48
【问题描述】:
我是 python 新手,我正在尝试使用一个库。它引发了一个异常,我正在尝试确定哪个异常。这就是我正在尝试的:
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 没有成功,我不知道该尝试什么。
【问题讨论】:
-
是的 - 我可能误读了那个 -
e.reason[0]['code']怎么样? -
回溯(最近一次调用最后一次):文件“descargar.py”,第 70 行,在
print e.reason[0]['code'] TypeError: string indices must be integers -
@alecxe 抱歉,这是前段时间,我不记得我做了什么,但我确实得到了代码(如我所愿)。不过,你的答案有效,所以我接受了:)
标签: python python-2.7 twitter tweepy