Azure Automation Runbook Python -Webhook数据
我正在准备Azure自动化,我正在使用Python SDK Automation Runbook,Runbook将由Webhook触发。我测试了Webhook,并且可以使用Webhook运行Python Runbook。 Automation Runbook作业状态完成
,我可以看到输出数据。
输入数据
"WebhookName":"webhookname","RequestBody":"{\"name\": \"Mike\", \"Nazwisko\": \"Tyson\"}","RequestHeader":{"Connection":"keep-alive","Accept":"*/*","Accept-Encoding":"gzip","Host":"XXXzzzWWW.webhook.wus2.azure-automation.net","User-Agent":"python-requests/2.27.1","x-ms-request-id":"AAAbbbCCC"}}
输出数据
['C:\\Temp\\ce51on0d.0c4\\XXvvBB', '{WebhookName:webhookname,RequestBody:{"name":', '"Mike",', '"Nazwisko":', '"Tyson"},RequestHeader:{Connection:keep-alive,Accept:*/*,Accept-Encoding:gzip,Host:AAAbbbCCC.webhook.wus2.azure-automation.net,User-Agent:python-requests/2.27.1,x-ms-request-id:AAbbCC}}']
Python脚本用于发送Webhook
import requests
import json
url = 'webhookURL'
payload = {'name': 'Mike','Nazwisko': 'Tyson'}
requests.post(url, data=json.dumps(payload), headers={'Content-Type': 'application/json'})
我的问题是,我如何从Webhook数据中的自动化Python Runbook中获取特定值。像:
var1 = payload.name
var2 = payload.nazwisko
我正在尝试使用sys
模块,但它无法正常工作。
import sys
test = str(sys.argv)
print(test)
I am preparing Azure automation, I am using Python SDK Automation runbook, runbook will be triggered by a webhook. I tested webhook, and I am able to run Python runbook using webhook. Automation Runbook Job status is Completed
, I can see output data.
input data
"WebhookName":"webhookname","RequestBody":"{\"name\": \"Mike\", \"Nazwisko\": \"Tyson\"}","RequestHeader":{"Connection":"keep-alive","Accept":"*/*","Accept-Encoding":"gzip","Host":"XXXzzzWWW.webhook.wus2.azure-automation.net","User-Agent":"python-requests/2.27.1","x-ms-request-id":"AAAbbbCCC"}}
output data
['C:\\Temp\\ce51on0d.0c4\\XXvvBB', '{WebhookName:webhookname,RequestBody:{"name":', '"Mike",', '"Nazwisko":', '"Tyson"},RequestHeader:{Connection:keep-alive,Accept:*/*,Accept-Encoding:gzip,Host:AAAbbbCCC.webhook.wus2.azure-automation.net,User-Agent:python-requests/2.27.1,x-ms-request-id:AAbbCC}}']
Python script for sending webhook
import requests
import json
url = 'webhookURL'
payload = {'name': 'Mike','Nazwisko': 'Tyson'}
requests.post(url, data=json.dumps(payload), headers={'Content-Type': 'application/json'})
My question is how can I get, in my Automation Python runbook, specific values from Webhook data. like:
var1 = payload.name
var2 = payload.nazwisko
I was trying with sys
module, but it does not work as expected.
import sys
test = str(sys.argv)
print(test)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
感谢您的帮助。我以类似的方式解决了:
“尝试”语句可以帮助我克服嵌套列表中的错误。
我必须在ARGV提供的清单上进行手术。这只是删除了多余的语法并将事物重组为字典格式。希望这对下一个人有帮助!
Thanks for the help here. I solved in a similar manner:
The "try" statement helps me overcome errors from nested lists when pushing everything into a dict.
I had to do surgery on the list that argv provided. This just removed the excess syntax and reorganizes things into dictionary format. Hope this helps the next person!
最后,我准备了我的Azure Automation Runbook,并按照预期的是Python Runbook代码。
Finally I prepared my Azure Automation runbook, and works as expected, below, Python runbook code.