Forum Stats

  • 3,726,727 Users
  • 2,245,248 Discussions


Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

“Error 'ResourceSummaryCollection' object is not subscriptable” OCI PythonSDK

SNC-Oracle Member Posts: 28 Employee

I have python script that queries OCI Compute Instances with a defined tag and value of test and will take the results and stop any instance with those tags. I am expecting the query to return the result as a json object of according to this:

However whenever I take the result and apply it to a variable I get the following error: "Error 'ResourceSummaryCollection' object is not subscriptable"

My function:

def do(signer):

    print("Searching for untagged instance", flush=True)

    # results = ""

    # message = ""

    # resp    = ""


        search_client = oci.resource_search.ResourceSearchClient(config={}, signer=signer)

        print("Search client initialized",flush=True)

        # PredefinedTag = "apps"

        # key= "test"

        # value= "test"

        # structured_search = oci.resource_search.models.StructuredSearchDetails(

        #         query="query instance resources where (definedTags.namespace = '{}' && definedTags.key = '{}' && definedTags.value = '{}')".format(PredefinedTag,key,value),

        #         type='Structured',

        #         matching_context_type=oci.resource_search.models.SearchDetails.MATCHING_CONTEXT_TYPE_NONE)

        structured_search = oci.resource_search.models.StructuredSearchDetails(

                query="query instance resources where (definedTags.namespace = 'apps' && definedTags.key = 'test' && definedTags.value = 'test')",




        results = search_client.search_resources(structured_search).data



        # print(results['items'][0]['identifier'])



        # instanceId = results['identifier']

        instanceId = results['items'][0]['identifier']


        resp = perform_action(signer, instanceId , 'STOP')



    except oci.exceptions.ServiceError as e:

            print('RQS Search failed with Service Error: {0}'.format(e),flush=True)


    except oci.exceptions.RequestException as e:

            print('RQS Search failed w/ a Request exception. {0}'.format(e),flush=True)


    return resp

Sign In or Register to comment.