reading response returns error python sdk OCI

395 views Asked by At

I am trying to read and pass the response of work requests in OCI for my compartment.

import oci
import configparser
import json
from oci.work_requests import WorkRequestClient

DEFAULT_CONFIG = "~/.oci/config"
DEFAULT_PROFILE = "DEFAULT"
config_file="config.json"
ab=[]

def config_file_parser(config_file):
    config=configparser.ConfigParser()
    config.read(config_file)
    profile=config.sections()
    for config_profile in profile:
        func1 = get_work_request(file=config_file, profile_name=config_profile)
        get_print_details(func1)


def get_work_request(file=DEFAULT_CONFIG, profile_name=DEFAULT_PROFILE):
    global oci_config, identity_client, work_request_client
    oci_config = oci.config.from_file(file, profile_name=profile_name)
    identity_client = oci.identity.identity_client.IdentityClient(oci_config)
    core_client = oci.core.ComputeClient(oci_config)
    work_request_client = WorkRequestClient(oci_config)
    work_requests = work_request_client.list_work_requests(oci_config["compartment"]).data
    print("{} Work Requests found.".format(len(work_requests)))
    return work_requests

def get_print_details(workrequest_id):
    resp = work_request_client.get_work_request(','.join([str(i["id"]) for i in workrequest_id]))
    wrDetails = resp.data

    print()
    print()
    print('=' * 90)
    print('Work Request Details: {}'.format(workrequest_id))
    print('=' * 90)
    print("{}".format(wrDetails))
    print()


if __name__ == "__main__":
    config_file_parser(config_file)

But while executing work_request_client.get_work_request I am getting TypeError: 'WorkRequestSummary' object is not subscriptable I have tried multiple times with making as object JSON but still the error remains, any way to solve or any leads would be great.

1

There are 1 answers

0
Joe On BEST ANSWER

I don't think get_work_request supports passing in multiple work request ids. You'd need to call get_work_request individually for each work request id.