Python TypeError:列表索引必须是整数或片,而不是带API的str

Python TypeError:列表索引必须是整数或片,而不是带API的str,python,json,list,api,Python,Json,List,Api,我正试图打印与此api一起发布的组合,但得到了TypeError:列表索引必须是整数或片,而不是str。请帮助 result是一个列表,因此您可能指的是x,因为这是您的项目: result = [{'line': 'johannsasuke@gmail.com:42ab89', 'sources': ['Taringa.net'], 'last_breach': '2017-08'}, {'line': 'johannsasuke@gmail.com:PEIN12345', 'sources':

我正试图打印与此api一起发布的组合,但得到了TypeError:列表索引必须是整数或片,而不是str。请帮助

result
是一个列表,因此您可能指的是
x
,因为这是您的项目:

result = [{'line': 'johannsasuke@gmail.com:42ab89', 'sources': ['Taringa.net'], 'last_breach': '2017-08'}, {'line': 'johannsasuke@gmail.com:PEIN12345', 'sources': ['Evony.com'], 'last_breach': '2016-07'}, {'line': 'johannsasuke@gmail.com:sasuke12345', 'sources': ['Animoto.com', 'Collection 1', 'xSplit'], 'last_breach': '2019-01'}, {'line': 'johannsasuke@gmail.com', 'sources': ['xSplit'], 'last_breach': '2013-11', 'email_only': 1}]

for x in result:

   if result['email_only']==1:

     pass

   else:

     print(result['line'])
印刷品:

johannsasuke@gmail.com:42ab89
johannsasuke@gmail.com:PEIN12345
johannsasuke@gmail.com:佐助12345

注意:我使用了
x.get()
,因为如果字典中不存在key
email\u only
(不引发异常),它将返回
None

@NathanWilliamson,注意使用
continue
而不是
pass
。这是
循环的惯例。
for x in result:
    if x.get("email_only") == 1:
        continue
    print(x["line"])