python - 读取响应返回错误 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
我已经多次尝试将 JSON 作为对象,但错误仍然存在,任何解决方法或任何线索都会很棒。
解决方案
我认为不get_work_request
支持传入多个工作请求 ID。您需要get_work_request
为每个工作请求 ID 单独调用。
推荐阅读
- vb.net - 在 RichTextBox 中获取实际的 SelectionStart 位置?
- node.js - 节点 - 将表与 Sequelize 关联
- arrays - 标记包含过滤器列表中单词的单元格
- json - 将两个相同文件的json文件合二为一
- java - 如何在 Android 10 中创建自定义目录“/storage/emulated/0/TestDir”?
- html - 如何通过自定义 CSS 更改阿拉伯语 RTL 下拉子菜单的方向?
- deployment - 管理代理产品上的就绪探测失败
- python - 如果我有中点、角度和长度,则获取一条线的端点
- mongodb - 猫鼬集成问题(又名 insertMany)
- swiftui - 似乎无法在 text() 和 textfield() 之间使用 Spacer()