我使用requests
库来查询F5大IP。我得到了虚拟服务器的列表。我需要做一个循环,从响应中获取每个VS name(VS1, VS2, VS3)
,以便在另一个请求中使用,比如
https://localhost/mgmt/tm/ltm/virtual/VS1
什么代码将从响应中获得每个名称值?我试过this,但没能成功
url = "https://bigipname.domain.local/mgmt/tm/ltm/virtual"
querystring = {"$select":"name"}
headers = {
'Content-Type': "application/json",
'Accept': "*/*",
'Cache-Control': "no-cache",
'Host': "bigipgname.domain.local",
'accept-encoding': "gzip, deflate",
'Connection': "keep-alive",
'cache-control': "no-cache"
}
response = requests.request("GET", url, headers=headers, params=querystring, verify=False)
我得到以下json格式的响应:
{'kind': 'tm:ltm:virtual:virtualcollectionstate', 'selfLink': 'https://localhost/mgmt/tm/ltm/virtual?$select=name&ver=13.1.1.2', 'items': [{'name': 'VS1'}, {'name': 'VS2'}, {'name': 'VS3'}]}
感谢您的帮助。谢谢
您可以使用列表理解来提取“项”
相关问题 更多 >
编程相关推荐