在 Azure Python SDK 中创建自动化帐户的错误请求
Bad Request creating Automation Account in Azure Python SDK
我正在尝试使用 Python SDK 创建一个新的 AutomationAccount。如果我获取、列出、更新或删除任何帐户都没有问题,但是当我尝试创建一个新帐户时出现 BadRequest 错误。
文档非常简单:AutomationAccountOperations Class > create_or_update()
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
from azure.identity import AzureCliCredential
from azure.mgmt.automation import AutomationClient
credential = AzureCliCredential()
automation_client = AutomationClient(credential, "xxxxx")
result = automation_client.automation_account.create_or_update("existing_rg", 'my_automation_account', {"location": "westeurope"})
print(f'Automation account {result.name} created')
这个小脚本向我抛出这个错误:
Traceback (most recent call last):
File ".\deploy.py", line 10
result = automation_client.automation_account.create_or_update("*****", 'my_automation_account', {"location": "westeurope"})
File "C:\Users\Dave\.virtualenvs\new-azure-account-EfYek8IT\lib\site-packages\azure\mgmt\automation\operations\_automation_account_operations.py", line 174, in create_or_update
raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat)
azure.core.exceptions.HttpResponseError: (BadRequest) {"Message":"The request body on Account must be present, and must specify, at a minimum, the required fields set to valid values."}
Code: BadRequest
Message: {"Message":"The request body on Account must be present, and must specify, at a minimum, the required fields set to valid values."}
我尝试在不同的 sdk 上使用此方法 (create_or_update),例如使用相同参数的 powershell,它成功了。
一些想法?
解决方法是设置 Azure SKU 参数。
出于某种原因,在 Powershell 上不是必需的,但在 Python SDK 上是必需的。现在这段代码成功创建了我的 AutomationAccount。
credential = AzureCliCredential()
automation_client = AutomationClient(credential, "xxxxx")
params = {"name": my_automation_account, "location": LOCATION, "tags": {}, "sku": {"name": "free"}}
result = automation_client.automation_account.create_or_update("existing_rg", 'my_automation_account', params)
print(f'Automation account {result.name} created')
关于这个的文档:
- AutomationAccountOperations Class > create_or_update
- AutomationAccountCreateOrUpdateParameters Class
- Sku Class
感谢@UpQuark
我正在尝试使用 Python SDK 创建一个新的 AutomationAccount。如果我获取、列出、更新或删除任何帐户都没有问题,但是当我尝试创建一个新帐户时出现 BadRequest 错误。
文档非常简单:AutomationAccountOperations Class > create_or_update()
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
from azure.identity import AzureCliCredential
from azure.mgmt.automation import AutomationClient
credential = AzureCliCredential()
automation_client = AutomationClient(credential, "xxxxx")
result = automation_client.automation_account.create_or_update("existing_rg", 'my_automation_account', {"location": "westeurope"})
print(f'Automation account {result.name} created')
这个小脚本向我抛出这个错误:
Traceback (most recent call last):
File ".\deploy.py", line 10
result = automation_client.automation_account.create_or_update("*****", 'my_automation_account', {"location": "westeurope"})
File "C:\Users\Dave\.virtualenvs\new-azure-account-EfYek8IT\lib\site-packages\azure\mgmt\automation\operations\_automation_account_operations.py", line 174, in create_or_update
raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat)
azure.core.exceptions.HttpResponseError: (BadRequest) {"Message":"The request body on Account must be present, and must specify, at a minimum, the required fields set to valid values."}
Code: BadRequest
Message: {"Message":"The request body on Account must be present, and must specify, at a minimum, the required fields set to valid values."}
我尝试在不同的 sdk 上使用此方法 (create_or_update),例如使用相同参数的 powershell,它成功了。
一些想法?
解决方法是设置 Azure SKU 参数。
出于某种原因,在 Powershell 上不是必需的,但在 Python SDK 上是必需的。现在这段代码成功创建了我的 AutomationAccount。
credential = AzureCliCredential()
automation_client = AutomationClient(credential, "xxxxx")
params = {"name": my_automation_account, "location": LOCATION, "tags": {}, "sku": {"name": "free"}}
result = automation_client.automation_account.create_or_update("existing_rg", 'my_automation_account', params)
print(f'Automation account {result.name} created')
关于这个的文档:
- AutomationAccountOperations Class > create_or_update
- AutomationAccountCreateOrUpdateParameters Class
- Sku Class
感谢@UpQuark