【发布时间】:2020-10-22 08:25:49
【问题描述】:
需要对以下代码进行哪些特定更改,以便使用 Python 请求模块和记录在 @987654321 的 Azure DevOps Services REST API 端点通过属性 name 和 isHosted 成功过滤代理池列表@?
当列表被{name=Default,isHosted=false} 过滤时,应该只返回 1 个代理池,如下所示,但问题是下面的代码返回所有代理池,包括具有不同名称的代理池和托管的代理池。
import requests
import os
import base64
import json
personal_access_token = ":"+os.environ["AZ_PERSONAL_ACCESS_TOKEN"]
headers = {}
headers['Content-type'] = "application/json"
headers['Authorization'] = b'Basic ' + base64.b64encode(personal_access_token.encode('utf-8'))
#Get a list of agent pools.
instance = "dev.azure.com/MyOrganization"
propVals = "{name=Default,isHosted=false}"
api_version = "5.1"
url = ("https://%s/_apis/distributedtask/pools?properties=%s?api-version=%s" % (instance, propVals, api_version))
r = requests.get(url, headers=headers)
print("r.status_code is: ", r.status_code)
print("r.json() is: ", r.json())
请注意,关于如何使用 Python 与 Azure DevOps Services API 集成的文档似乎很少。另外,请注意我们使用的是 Python 3.7.6。
【问题讨论】:
标签: python python-3.x azure azure-devops azure-devops-rest-api