2 Replies Latest reply on Dec 3, 2014 7:53 AM by thales

    JSON KeyError when using DES Rest API


      Has anyone else gotten json errors recently? My scripts were working correctly yesterday, and today I am getting a Key Error when looping through the json return.


      KeyError: 'list'


      #Add place name and placeID to a dictionary.
      placeDict = {}
      for dataItem in jsonData["list"]:
          name = dataItem["displayName"]
          name2 = name.encode('ascii', 'replace')
          placeID = dataItem["placeID"]
          #print "{}: {}".format(name2, "placeID")
          placeDict.update({name2: placeID})
      #Print the place and placeID in a dictionary
      print placeDict
        • Re: Json KeyError when using Rest API

          Alright, so apparently the admin password that this example script was using got changed. Now I am able to access the "list".


          But I am still having problems with the DES api and specifically the "containerType":


          cType = item["activity"]["actionObject"]["containerType"]


          KeyError: 'containerType'


          Am I calling it correctly?


          for item in jsonData["list"]:
                  cType = item["activity"]["actionObject"]["containerType"]
          • Re: Json KeyError when using Rest API

            I finally figured out the problem here. It appears that the DES API is returning different JSON keys within the same call. From what I can tell if a user creates a discussion and then deletes it, then the action is still there but the underlying data is removed. Therefore information such as status, containerID, containerType, url, subject, pullPath does not exist in that returned item. When I try to pull the containerType, it is missing and throws the error.


            I am logging a support case to confirm the exact case. I am guessing that the backend takes some time to refresh the database, and I am catching new activity (deleted) before the database and refresh.