读取响应 returns 错误 python sdk OCI
reading response returns error python sdk OCI
我正在尝试读取并传递 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
我已经尝试了多次 making as object JSON 但错误仍然存在,任何解决方法或任何线索都是太好了。
我认为 get_work_request
不支持传入多个工作请求 ID。您需要为每个工作请求 ID 单独调用 get_work_request
。
我正在尝试读取并传递 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
我已经尝试了多次 making as object JSON 但错误仍然存在,任何解决方法或任何线索都是太好了。
我认为 get_work_request
不支持传入多个工作请求 ID。您需要为每个工作请求 ID 单独调用 get_work_request
。