我的 Python 代码中出现以下错误:
if data['result'] == 0:
TypeError: list indices must be integers, not str
以下是代码:
data = urllib.urlencode(parameters)
req = urllib2.Request(url, data)
try:
response = urllib2.urlopen(req)
except urllib2.URLError, e:
self.redirect('/error')
json_post = response.read()
data = json.loads(json_post)
response_dict = simplejson.loads(json_post)
virustotal = VirusTotal()
if data['result'] == 0:
virustotal_result = True
elif data['result'] == -2:
self.response.out.write("API Request Rate Limit Exceeded<br/>")
elif data['result'] == -1:
self.response.out.write("API Key provided is wrong<br/>")
elif data['result'] == 1:
self.response.out.write("Time Stamp : %s<br/>"% data['report'][0])
我知道数据是一个列表。所以我也把它改成了整数,但是代码显示了范围错误。请帮忙??