我刚刚编写了一个解析API数据的程序。该API以 JSON 格式返回数据。在尝试解析时,它给出了一个键错误。
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"
的子键。 - Morgan Thrapp