我刚刚制作了一个程序来解析api中的一些数据。 api以JSON格式返回数据。当我尝试分析它,它给了我一个关键的错误Python:解析JSON时得到Keyerror
Traceback (most recent call last):
File "test.py", line 20, in <module>
print(parsed_json['plain'])
KeyError: 'plain'
这是一个重要的部分代码(剩下的只是制作的URL,工作完全正常)
response = urllib.request.urlopen(url2).read()
strr = str(response)
if "plain" in strr:
parsed_json = json.loads(response.decode("UTF-8"))
print(parsed_json['plain'])
elif "INVALID HASH" in strr:
print("You have entered an invalid hash.")
elif "NOT FOUND" in strr:
print("The hash is not found")
elif "LIMIT REACHED" in strr:
print("You have reached the max requests per minute, please try again in one minute.")
我我试图在普通的领域获得数据。 下面是从API输出:
{
"REQUEST": "FOUND",
"739c5b1cd5681e668f689aa66bcc254c": {
"plain": "test",
"hexplain": "74657374",
"algorithm": "MD5X5PLAIN"
}
}
除非我失去了一些东西,它看起来像“plain”是“739c5b1cd5681e668f689aa66bcc254c”的子项。 –
@MorganThrapp我想在平淡之后获得“测试”。不是本身。 – Uber
'“test”'是“plain”键的值吗? –