尝试创建 Oracle BMC SecurityList 时出现 AttributeError
Getting an AttributeError when I try to create a Oracle BMC SecurityList
我正在尝试在 Oracle BMC 中自动创建资源。我有这个 python 代码:
import oraclebmc
config = oraclebmc.config.from_file()
network = oraclebmc.core.virtual_network_client.VirtualNetworkClient(config)
compartment_id = ...
vcn_id = ....
details = oraclebmc.core.models.CreateSecurityListDetails()
details.compartment_id = compartment_id
details.display_name = "baseline"
details.ingress_security_rules = ()
details.egress_security_rules = ()
details.vcn_id = vcn_id
network.create_security_list(details)
但是当我 运行 这段代码时,我得到:
Traceback (most recent call last):
File "deploy/cloudresources/foo.py", line 16, in <module>
network.create_security_list(details)
File "/Users/jwmcclai/bmcs_env/lib/python2.7/site-packages/oraclebmc/core/virtual_network_client.py", line 668, in create_security_list
response_type="SecurityList")
File "/lib/python2.7/site-packages/oraclebmc/base_client.py", line 124, in call_api
body = self.sanitize_for_serialization(body)
File "/lib/python2.7/site-packages/oraclebmc/base_client.py", line 230, in sanitize_for_serialization
for key, val in obj_dict.items()}
File "/lib/python2.7/site-packages/oraclebmc/base_client.py", line 230, in <dictcomp>
for key, val in obj_dict.items()}
File "/lib/python2.7/site-packages/oraclebmc/base_client.py", line 226, in sanitize_for_serialization
for attr, _ in obj.swagger_types.items()
AttributeError: 'tuple' object has no attribute 'swagger_types'
我可以通过控制台创建安全列表,我可以使用 Python API 创建其他资源(VCN、实例等)。有什么想法吗?
谢谢
这是因为您将安全规则字段定义为元组,而不是列表。
您的代码:
details.ingress_security_rules = ()
details.egress_security_rules = ()
应该是:
details.ingress_security_rules = []
details.egress_security_rules = []
正如docs提到的,这些字段应该是列表类型,而不是元组类型。
我正在尝试在 Oracle BMC 中自动创建资源。我有这个 python 代码:
import oraclebmc
config = oraclebmc.config.from_file()
network = oraclebmc.core.virtual_network_client.VirtualNetworkClient(config)
compartment_id = ...
vcn_id = ....
details = oraclebmc.core.models.CreateSecurityListDetails()
details.compartment_id = compartment_id
details.display_name = "baseline"
details.ingress_security_rules = ()
details.egress_security_rules = ()
details.vcn_id = vcn_id
network.create_security_list(details)
但是当我 运行 这段代码时,我得到:
Traceback (most recent call last):
File "deploy/cloudresources/foo.py", line 16, in <module>
network.create_security_list(details)
File "/Users/jwmcclai/bmcs_env/lib/python2.7/site-packages/oraclebmc/core/virtual_network_client.py", line 668, in create_security_list
response_type="SecurityList")
File "/lib/python2.7/site-packages/oraclebmc/base_client.py", line 124, in call_api
body = self.sanitize_for_serialization(body)
File "/lib/python2.7/site-packages/oraclebmc/base_client.py", line 230, in sanitize_for_serialization
for key, val in obj_dict.items()}
File "/lib/python2.7/site-packages/oraclebmc/base_client.py", line 230, in <dictcomp>
for key, val in obj_dict.items()}
File "/lib/python2.7/site-packages/oraclebmc/base_client.py", line 226, in sanitize_for_serialization
for attr, _ in obj.swagger_types.items()
AttributeError: 'tuple' object has no attribute 'swagger_types'
我可以通过控制台创建安全列表,我可以使用 Python API 创建其他资源(VCN、实例等)。有什么想法吗?
谢谢
这是因为您将安全规则字段定义为元组,而不是列表。
您的代码:
details.ingress_security_rules = ()
details.egress_security_rules = ()
应该是:
details.ingress_security_rules = []
details.egress_security_rules = []
正如docs提到的,这些字段应该是列表类型,而不是元组类型。