在python中使用azure REST api创建Runbook作为草稿我面临错误......!

时间:2016-05-17 14:50:02

标签: python api rest azure azure-automation

我需要创建Azure自动化帐户,并且我想在自动化帐户下创建运行手册以自动安排VM

我创建Azure自动化帐户的步骤。

  1. 使用API​​创建云服务  https://management.core.windows.net/sdjgsdgj-abcd-2323-98cd-3bd6bcf93702/cloudServices/cloudsername

  2. 下一步,我是使用上面的API在创建的云服务下创建Azure自动化帐户。 https://management.core.windows.net/sdjgsdgj-abcd-2323-98cd-3bd6bcf93702/cloudServices/cloudsername/resources/automation/AutomationAccount/testacc2?resourceType=AutomationAccount&detailLevel=Full&resourceProviderNamespace=automation'

  3. 之后,我想在创建自动化帐户下创建Runbook,我在Python中使用以下API

  4. import adal
    import requests
    import json
    
    token_response = adal.acquire_token_with_username_password(
    'https://login.windows.net/rapiddirectory.onmicrosoft.com',
    'test@xyz.onmicrosoft.com',
    'abcd'
    )
    access_token = token_response.get('accessToken')
    create_run_draft = 'https://management.core.windows.net/sdjgsdgj-abcd-2323-98cd-3bd6bcf93702/cloudServices/cloudsername/resources/automation/~/automationAccounts/testacc2/runbooks/write-helloworld/draft?api-version=2014-12-08'
    
    param3 = {
       "tags":{
      "Testing":"show value",
      "Source":"TechNet Script Center"
       },
    "properties":{
      "description":"Hello world",
      "runbookType":"Script",
      "logProgress":"false",
      "logVerbose":"false",
      "draft":{
         "draftContentLink":{
            "uri":"https://gallery.technet.microsoft.com/scriptcenter/The-Hello-World-of-Windows-81b69574/file/111354/1/Write-HelloWorld.ps1",
            "contentVersion":"1.0.0.0",
            "contentHash":{
               "algorithm":"sha256",
               "value":"EqdfsYoVzERQZ3l69N55y1RcYDwkib2+2X+aGUSdr4Q="
            }
         }
      }
    }
    }
    headers2 = {'x-ms-version' : '2013-06-01','Content-Type' : 'application/json',"Authorization": 'Bearer ' + access_token}
    output = requests.put(create_run_draft,headers=headers2,data=param3).text
    print output
    

    我正在使用Python编程语言来实现Azure REST API

    我收到以下错误

    <Error xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.
    org/2001/XMLSchema-instance"><Code>InternalError</Code><Message>The server encou
    ntered an internal error. Please retry the request.</Message></Error>
    

    请帮我解决这个问题我正在努力解决错误

1 个答案:

答案 0 :(得分:0)

可能是因为您将logProgress和logVerbose的值作为字符串("false")而不是布尔值(false)传递。

这对我有用:

创建Runbook:

PUT https://management.core.windows.net/90751b51-7cb6-4480-8dbd-e199395b296f/cloudservices/OaaSCS/resources/automation/~/automationAccounts/JoeAutomationAccount/runbooks/testabc?api-version=2014-12-08

请求正文:

{ "properties": { "logVerbose": false, "logProgress": false, "runbookType": "Script", "draft": { "inEdit": false, "creationTime": "0001-01-01T00:00:00+00:00", "lastModifiedTime": "0001-01-01T00:00:00+00:00" } }, "name": "testabc" }

上传草稿内容:

PUT https://management.core.windows.net/90751b51-7cb6-4480-8dbd-e199395b296f/cloudservices/OaaSCS/resources/automation/~/automationAccounts/JoeAutomationAccount/runbooks/testabc/draft/content?api-version=2014-12-08

请求正文:

workflow testabc { "hello" }