[英]How to authenticate REST API in Azure Runbooks with Python?
I'm trying to access the quota list/read api from a python runbook in an automation account - but how do I authenticate it?我正在尝试从自动化帐户中的 python 运行手册访问配额列表/读取 api - 但如何对其进行身份验证?
I'm reading.我正在阅读。 I need to pass a bearer auth token in the header but the tutorials I find are all done via Postman which doesn't make sense since this is an internally ran script.
我需要在 header 中传递不记名身份验证令牌,但我发现的教程都是通过 Postman 完成的,因为这是一个内部运行的脚本,所以没有意义。
API: https://docs.microsoft.com/en-us/rest/api/reserved-vm-instances/quota/list?tabs=HTTP API: https://docs.microsoft.com/en-us/rest/api/reserved-vm-instances/quota/list?tabs=HTTP
I found this in the documentation, but it looks like this is for an externally ran python script?我在文档中找到了这个,但看起来这是针对外部运行的 python 脚本? https://docs.microsoft.com/en-us/azure/automation/learn/automation-tutorial-runbook-textual-python-3
https://docs.microsoft.com/en-us/azure/automation/learn/automation-tutorial-runbook-textual-python-3
Any help here would be much appreciated.在这里的任何帮助将不胜感激。
Here is a basic example of passing headers in a python api call.这是在 python api 调用中传递标头的基本示例。 You can add the headers needed in the headers variable here to make a successful api call.
您可以在此处添加 headers 变量中所需的标头,以进行成功的 api 调用。
Here is the documentation on the python requests module. 这是 python 请求模块的文档。
import requests
# Make an API call and store the response
url = 'https://api.github.com/search/repositories?q=language:python&sort=stars'
headers = {'Accept': 'application/vnd.github.v3+json'}
r = requests.get(url, headers=headers)
print(f'Status Code: {r.status_code}')
# Store the response as a variable
response_dict = r.json()
print(f"Total repositories: {response_dict['total_count']}")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.