[英]Can't get the subnet id of azure using python
I want to get the resource id of a su.net in a virtual.network in azure using python, the command i have used is this line: su.nets.network_client.su.nets.get(resource_group,'XXX','XXX')我想使用 python 在 azure 中的 virtual.network 中获取 su.net 的资源 ID,我使用的命令是这一行:su.nets.network_client.su.nets.get(resource_group,'XXX',' XXX')
But what I get is an error: HttpResponseError: (InvalidApiVersionParameter) The api-version '2021-02-01' is invalid.但我得到的是一个错误:HttpResponseError: (InvalidApiVersionParameter) The api-version '2021-02-01' is invalid。 The supported versions are '2021-04-01,2021-01-01,2020-10-01,2020-09-01,2020-08-01,2020-07-01,2020-06-01,2020-05-01,2020-01-01,2019-11-01,2019-10-01,2019-09-01,2019-08-01,2019-07-01,2019-06-01,2019-05-10,2019-05-01,2019-03-01,2018-11-01,2018-09-01,2018-08-01,2018-07-01,2018-06-01,2018-05-01,2018-02-01,2018-01-01,2017-12-01,2017-08-01,2017-06-01,2017-05-10,2017-05-01,2017-03-01,2016-09-01,2016-07-01,2016-06-01,2016-02-01,2015-11-01,2015-01-01,2014-04-01-preview,2014-04-01,2014-01-01,2013-03-01,2014-02-26,2014-04'.支持的版本是'2021-04-01,2021-01-01,2020-10-01,2020-09-01,2020-08-01,2020-07-01,2020-06-01,2020-05 -01,2020-01-01,2019-11-01,2019-10-01,2019-09-01,2019-08-01,2019-07-01,2019-06-01,2019-05-10 ,2019-05-01,2019-03-01,2018-11-01,2018-09-01,2018-08-01,2018-07-01,2018-06-01,2018-05-01,2018 -02-01,2018-01-01,2017-12-01,2017-08-01,2017-06-01,2017-05-10,2017-05-01,2017-03-01,2016-09 -01,2016-07-01,2016-06-01,2016-02-01,2015-11-01,2015-01-01,2014-04-01-预览,2014-04-01,2014-01 -01,2013-03-01,2014-02-26,2014-04'。 I have tried different api versions but it's getting me errors.Any idea please?我尝试了不同的 api 版本,但它让我出错。有什么想法吗? The version of azure-mgmt.network I used is 19.0.0我使用的azure-mgmt.network版本是19.0.0
Please make sure that you have the below two models installed first before executing the script:请确保在执行脚本之前先安装了以下两个模型:
pip install azure-mgmt.network
pip install azure-identity
Then use the below script to get the su.net-id
of specific su.net present in your subscription:然后使用以下脚本获取订阅中存在的特定 su.net 的su.net-id
:
from azure.identity import AzureCliCredential
from azure.mgmt.network import NetworkManagementClient
credential = AzureCliCredential()
subscription_id = "948d4068-xxxx-xxxx-xxxx-e00a844e059b"
network_client = NetworkManagementClient(credential, subscription_id)
resource_group_name = "ansumantest"
location = "West US 2"
virtual_network_name = "ansuman-vnet"
subnet_name = "acisubnet"
Subnet=network_client.subnets.get(resource_group_name, virtual_network_name, subnet_name)
print(Subnet.id)
Output: Output:
Note: I am using pip version pip 21.2.4 and (python 3.9)
.注意:我使用的是 pip 版本pip 21.2.4 and (python 3.9)
。 The pip models version that I am using are as below:我使用的pip型号版本如下:
I am using the same.network model version as you.我使用的是和你一样的.network model 版本。 But if you are still facing the issue then trying installing the new one ie 19.1.0 .但是,如果您仍然面临问题,请尝试安装新版本,即19.1.0 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.