Azure / Azure/azure-rest-api-specs-examples

Method client.service_tags.list() returns an object instead of a dictionary

Open
#5,505 0 comments 0 reactions 1 assignee Claimed by @msyyc View on GitHub
Dominant language
No language data
Stars
40
Forks
23
Avg merge
23h 36m
Merged PRs (30d)
172

Description

### Link to sample

https://learn.microsoft.com/en-us/rest/api/virtualnetwork/service-tags/list?view=rest-virtualnetwork-2024-05-01&tabs=Python#get-list-of-service-tags

### Library name and version

azure-mgmt-network NetworkManagementClient 28.1.0

### Language of the Sample

- [ ] C#/.NET
- [ ] Java
- [ ] JavaScript/TypedScript
- [x] Python
- [ ] Golang
- [ ] Other - Please specify in Issue details field

### Sample Issue Type

- [x] Sample not working
- [ ] Sample missing
- [ ] Do not understand sample

### Issue details

The client.service_tags.list() method returns a ServiceTagInformation object instead of a dictionary. The response from `client.service_tags.list()` returns the object ``. To solve it, I changed the code to:

```python
from azure.identity import DefaultAzureCredential

from azure.mgmt.network import NetworkManagementClient

import json

"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-network
# USAGE
python service_tags_list.py

Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""

def main():
client = NetworkManagementClient(
credential=DefaultAzureCredential(),
subscription_id="subId",
)

response = client.service_tags.list(
location="westcentralus",
)
print(json.dumps(response.as_dict() if response else None, indent=4))

# x-ms-original-file: specification/network/resource-manager/Microsoft.Network/stable/2024-05-01/examples/ServiceTagsList.json
if __name__ == "__main__":
main()
```

### Expected behavior

Return from `client.service_tags.list()`:

```json
{
"name": "public",
"id": "/subscriptions/subId/providers/Microsoft.Network/serviceTags/public",
"type": "Microsoft.Network/serviceTags",
"changeNumber": "63",
"cloud": "Public",
"values": [
{
"name": "ApiManagement",
"id": "ApiManagement",
"properties": {
"changeNumber": "7",
"region": "",
"systemService": "AzureApiManagement",
"addressPrefixes": [
"13.64.39.16/32",
"40.74.146.80/31",
"40.74.147.32/28"
]
}
},
{
"name": "ApiManagement.AustraliaCentral",
"id": "ApiManagement.AustraliaCentral",
"properties": {
"changeNumber": "2",
"region": "australiacentral",
"systemService": "AzureApiManagement",
"addressPrefixes": [
"20.36.106.68/31",
"20.36.107.176/28"
]
}
},
{
"name": "AppService",
"id": "AppService",
"properties": {
"changeNumber": "13",
"region": "",
"systemService": "AzureAppService",
"addressPrefixes": [
"13.64.73.110/32",
"191.235.208.12/32",
"191.235.215.184/32"
]
}
},
{
"name": "ServiceBus",
"id": "ServiceBus",
"properties": {
"changeNumber": "10",
"region": "",
"systemService": "AzureServiceBus",
"addressPrefixes": [
"23.98.82.96/29",
"40.68.127.68/32",
"40.70.146.64/29"
]
}
},
{
"name": "ServiceBus.EastUS2",
"id": "ServiceBus.EastUS2",
"properties": {
"changeNumber": "1",
"region": "eastus2",
"systemService": "AzureServiceBus",
"addressPrefixes": [
"13.68.110.36/32",
"40.70.146.64/29"
]
}
}
],
"nextLink": "https://management.azure.com/subscriptions/subid/providers/Microsoft.Network/locations/centraluseuap/serviceTags?api-version=2020-06-01&changenumber=changenumber&$skipToken={skipToken}"
}
```

### Actual behavior

Return from `client.service_tags.list()`:

```json
{
"additional_properties":{},
"name":"Public",
"id":"",
"type":"Microsoft.Network/serviceTags",
"change_number":"181",
"cloud":"Public",
"values":[
,
,
,
,
,
,
,
,

],
"next_link":""
```

### Reproduction Steps

Create a file called, `test_tags.py`, code:

> Change the `subId`

```pyton
from azure.identity import DefaultAzureCredential

from azure.mgmt.network import NetworkManagementClient

"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-network
# USAGE
python service_tags_list.py

Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""

def main():
client = NetworkManagementClient(
credential=DefaultAzureCredential(),
subscription_id="subId",
)

response = client.service_tags.list(
location="westcentralus",
)
print(response)

# x-ms-original-file: specification/network/resource-manager/Microsoft.Network/stable/2024-05-01/examples/ServiceTagsList.json
if __name__ == "__main__":
main()
```

Execute the command `python3 test_tags.py`, see the results.

Change the code to:

> Change the `subId`

```python
from azure.identity import DefaultAzureCredential

from azure.mgmt.network import NetworkManagementClient

# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-network
# USAGE
python service_tags_list.py

Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""

def main():
client = NetworkManagementClient(
credential=DefaultAzureCredential(),
subscription_id="subId",
)

response = client.service_tags.list(
location="westcentralus",
)
print(json.dumps(response.as_dict() if response else None, indent=4))

# x-ms-original-file: specification/network/resource-manager/Microsoft.Network/stable/2024-05-01/examples/ServiceTagsList.json
if __name__ == "__main__":
main()
```

### Environment

Python: 3.12.3

Pip:
azure-common==1.1.28
azure-core==1.32.0
azure-identity==1.20.0
azure-mgmt-core==1.5.0
azure-mgmt-network==28.1.0
certifi==2025.1.31
cffi==1.17.1
charset-normalizer==3.4.1
cryptography==44.0.1
idna==3.10
isodate==0.7.2
msal==1.31.1
msal-extensions==1.2.0
portalocker==2.10.1
pycparser==2.22
PyJWT==2.10.1
requests==2.32.3
six==1.17.0
typing_extensions==4.12.2
urllib3==2.3.0

VS Code:
Version: 1.97.1 (user setup)
Commit: e249dada235c2083c83813bd65b7f4707fb97b76
Date: 2025-02-10T13:13:58.153Z
Electron: 32.2.7
ElectronBuildId: 10660205
Chromium: 128.0.6613.186
Node.js: 20.18.1
V8: 12.8.374.38-electron.0
OS: Windows_NT x64 10.0.26100

WSL:
Distributor ID: Ubuntu
Description: Ubuntu 24.04.1 LTS
Release: 24.04
Codename: noble

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.