我正在尝试在 OCI 中为我的隔间读取并传递工作请求的响应。
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)
但是在执行work_request_client.get_work_request
时,TypeError: 'WorkRequestSummary' object is not subscriptable
我已经多次尝试将 JSON 作为对象,但错误仍然存在,任何解决方法或任何线索都会很棒。