简体   繁体   English

如何在 Azure Runbooks 中使用 ZA7F5F35426B9637411FCZ3231B 验证 REST API

[英]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.

相关问题 Azure Runbook-解析Python参数 - Azure Runbooks - Parse Python Params Azure BLOB PUT Rest api - 无法使用 ZA7F5F353426B9238217316 进行身份验证 - Azure BLOB PUT Rest api - Not able to authenticate with Python 如何编写 Python 脚本以对 Azure DevOps REST API 进行身份验证并获取访问令牌? - How to write a python script to authenticate to Azure DevOps REST API and get the access token? 如何使用Python中的Rest API对Azure数据目录进行身份验证并从中获取目录 - How do i authenticate to and get catalog from Azure Data Catalog using Rest API in Python 使用Python 2.7对Tableau REST API进行身份验证 - Authenticate Tableau REST API using Python 2.7 Python - 如何验证服务器和 api? - Python - how to authenticate the server and the api? 如何使用 Python REST API 在 Azure DevOps 中更新测试结果? - How to Update Test Results in Azure DevOps with Python REST API? 如何使用Python REST API在Azure DevOps中检索测试结果? - How to retrieve Test Results in Azure DevOps with Python REST API? Azure Rest Api。 如何从工作项下载附件? Python - Azure Rest Api. How to download an attachment from the workitem? Python 如何使用 python 中的存储帐户密钥对 azure 存储 api 请求进行身份验证? - How to authenticate an azure storage api request using a storage account key in python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM