Python error - TypeError: create_or_update() takes 5 positional arguments but 6 were given

Python error - TypeError: create_or_update() takes 5 positional arguments but 6 were given

我是 Python 的新手,我正在尝试在 Azure 门户上创建防火墙规则。但是我收到以下错误 TypeError: create_or_update() takes 5 positional arguments but 6 were given

到目前为止,这是我的 python 脚本:

from azure.mgmt.resource.resources import ResourceManagementClient
from azure.mgmt.sql import SqlManagementClient

GROUP_NAME = 'xxxxxxxxx'
SERVER_NAME = 'xxxxxxxxx'
SUBSCRIPTION_ID = 'xxxxxxxxx'

credential = DefaultAzureCredential(
    exclude_interactive_browser_credential=False)

client = ResourceManagementClient(
       credential=credential,
       subscription_id=SUBSCRIPTION_ID)

for resource_group in client.resource_groups.list():
    print(f"Resource group: {resource_group.name}")

print(f"Successful credential: {credential._successful_credential.__class__.__name__}")

client = SqlManagementClient(credential, SUBSCRIPTION_ID)

print("Add firewall rule")
# Open access to this server for IPs
firewall_rule = client.firewall_rules.create_or_update(
    GROUP_NAME,
    SERVER_NAME,
    "test_rule",
    "123.123.123.123",
    "123.123.123.123"
    )

如果你查看 create_or_update 定义 here,

create_or_update(resource_group_name, server_name, firewall_rule_name, parameters, **kwargs)

您会注意到 parametersFirewallRule 类型。你能尝试创建一个这种类型的对象并在你的方法中使用它吗?类似于:

firewallRule = FirewallRule(name="Something", start_ip_address="123.123.123.123", end_ip_address="123.123.123.123")
firewall_rule = client.firewall_rules.create_or_update(
    GROUP_NAME,
    SERVER_NAME,
    "test_rule",
    firewallRule
    )