Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 尝试验证任何ARM模板,但得到:';转换值时出错<;。。。MyTemplate…>;要键入';。。。。Templates.Schema.Template';_Python_Azure_Validation_Arm Template - Fatal编程技术网

Python 尝试验证任何ARM模板,但得到:';转换值时出错<;。。。MyTemplate…>;要键入';。。。。Templates.Schema.Template';

Python 尝试验证任何ARM模板,但得到:';转换值时出错<;。。。MyTemplate…>;要键入';。。。。Templates.Schema.Template';,python,azure,validation,arm-template,Python,Azure,Validation,Arm Template,我试图验证一个arm模板-任何arm模板-但我总是得到相同的错误: The request content was invalid and could not be deserialized: 'Error converting value " { ... }" to type 'Microsoft.WindowsAzure.ResourceStack.Frontdoor.Templates.Schema.Template'. Path 'properties.template', line 1

我试图验证一个arm模板-任何arm模板-但我总是得到相同的错误:

The request content was invalid and could not be deserialized: 'Error converting value "
{
...
}" to type 'Microsoft.WindowsAzure.ResourceStack.Frontdoor.Templates.Schema.Template'. Path 'properties.template', line 1, position 1202.'.
我在azure门户上创建了ARM模板并将其插入:

#!/usr/bin/env python3                                                                                                                                                                   

# https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-authoring-templates                                                                                       
t='''                                                                                                                                                                                    
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1",
    "apiProfile": "",
    "parameters": {
        "testType": {
            "type": "string",
            "defaultValue": "Standard_LRS",
            "allowedValues": [
                "Standard_LRS",
                "Standard_ZRS",
                "Standard_GRS",
                "Standard_RAGRS",
                "Premium_LRS"
            ]
        }
    },
    "variables": {
        "testName": "[concat('test', uniqueString(resourceGroup().id))]"
    },
    "functions": [],
    "resources": [
        {
            "name": "[variables('testName')]",
            "type": "Microsoft.Storage/storageAccounts",
            "location": "[resourceGroup().location]",
            "apiVersion": "2015-06-15",
            "dependsOn": [],
            "tags": {
                "displayName": "test"
            },
            "properties": {
                "accountType": "[parameters('testType')]"
            }
        }
    ],
    "outputs": {}
}    

'''
from azure.common.client_factory import get_client_from_cli_profile
from azure.mgmt.resource import ResourceManagementClient
c = get_client_from_cli_profile(ResourceManagementClient)

print(c.deployments.validate('PAWS_Resources', 'food', c.models().DeploymentProperties(mode='incremental', template=t)).error.message)
根据文件:

模板对象:模板内容。您在创建时使用此元素 希望直接在请求中传递模板语法,而不是 链接到现有模板。它可以是JObject或格式良好的JSON 字符串。使用templateLink属性或template属性, 但不是两者都有

但是,它需要的是python对象,而不是“格式良好的JSON字符串”


删除模板数据周围的引号可以使其正常工作。

如果验证空模板怎么办?结果与文档相反,它需要一个python对象作为模板,而不是json字符串。唉。