这里有什么问题:TypeError:字符串索引必须是整数,而不是str

时间:2015-02-21 09:21:47

标签: python tweepy

if e.message[0]['code'] == 32: ##Account suspended : [{u'message': u'Could not authenticate you', u'code': 32}]': ##Account suspended : [{u'message': u'Could not authenticate you', u'code': 32}]

TypeError:字符串索引必须是整数,而不是str

我认为e是[{u'message': u'Could not authenticate you', u'code': 32}]

什么是问题?

1 个答案:

答案 0 :(得分:1)

你明确地错误地访问它,因为消息和代码是彼此并排的,代码不属于消息。但是您的错误消息也与您认为e的内容不一致。请尝试以下选项:e.codee["code"]e[0].codee[0]["code"]