在python中使用azurerestapi创建runbook作为草稿时,我遇到了一个错误。。。!

2024-09-30 12:22:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要创建Azure自动化帐户,我想在Automation帐户下创建运行手册,以便自动调度虚拟机的

我创建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. 之后,我想在create automation帐户下创建runbook,为此我使用Python中的下面的API

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编程语言为azurerestapi实现这一点

我得到下面的错误

^{pr2}$

请帮我解决这个问题我正在与错误作斗争


Tags: httpscoreimporttokennetwindowscreate帐户
1条回答
网友
1楼 · 发布于 2024-09-30 12:22:49

可能是因为您将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" }

相关问题 更多 >

    热门问题