从http响应获取特定值

2024-10-02 00:38:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用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'}]}

感谢您的帮助。谢谢


Tags: namehttpslocalhosturlcachedomainvirtualrequests

热门问题