gpt4 book ai didi

python - 在 python 中使用 azure REST api 将 Runbook 创建为草稿时,我遇到了错误...!

转载 作者:行者123 更新时间:2023-12-03 04:30:39 25 4
gpt4 key购买 nike

我需要创建 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

import adal
import requests
import json

token_response = adal.acquire_token_with_username_password(
'https://login.windows.net/rapiddirectory.onmicrosoft.com',
'<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dbafbea8af9ba3a2a1f5b4b5b6b2b8a9b4a8b4bdaff5b8b4b6" rel="noreferrer noopener nofollow">[email protected]</a>',
'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>

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

最佳答案

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

这对我有用:

创建运行手册:

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

请求正文:

{
“特性”: {
“logVerbose”:假,
“日志进度”:假,
"runbookType": "脚本",
“草稿”: {
“编辑中”:假,
"创建时间": "0001-01-01T00:00:00+00:00",
“最后修改时间”:“0001-01-01T00:00:00+00:00”
}
},
“名称”:“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

请求正文:

工作流程 testabc {
“你好”
}

关于python - 在 python 中使用 azure REST api 将 Runbook 创建为草稿时,我遇到了错误...!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37279493/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com