Python throws a keyword error when I try to retrieve a json metadata from a website

I want to iterate and fetch a part of json metadata The code below throws a traceback keyword error: ‘metadata’ when I run the code below. I dont know if the error is because of the function printResultS or it is only because of the keyword or argument “metadata”

import urllib.request
import json

def printResult(data):
    theJSON = json.loads(data)
    
    if "title" in theJSON["metadata"]:
        print(theJSON["metadata"]["title"])
        
    count = theJSON ["metadata"]["count"]
    print(str(count)+ "events recorded")

def main():   
    webUrldata = (
     
         "https://www.sciencebase.gov/catalog/item/5d88ea50e4b0c4f70d0ab3c0?format=json")
    webUrl = urllib.request.urlopen(webUrldata)
    print('Get request:'+ str(webUrl.getcode()))
    
    if (webUrl.getcode() == 200):
        data = webUrl.read()
        printResult(data)
    else:
        print("recieved error")

if __name__ == "__main__":
    main()

error

et request:200
Traceback (most recent call last):
  File /xample 3.py", line 27, in <module>
    main()
  File "/xample 3.py", line 22, in main
    printResult(data)
  File "/xample 3.py", line 7, in printResult
    if "title" in theJSON["metadata"]:
KeyError: 'metadata'

Answer

There is no metadata present

theJSON= json.loads(data).get("metadata")
print(theJSON)

gives –

None

&

theJSONkeys = json.loads(data).keys()
print(theJSONkeys)

gives

link
relatedItems
id
identifiers
title
summary
body
citation
purpose
provenance
maintenanceUpdateFrequency
hasChildren
parentId
contacts
webLinks
systemTypes
tags
dates
spatial
files
distributionLinks
previewImage