Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to list billing accounts using the Azure SDK for python #39933

Closed
juniinacio opened this issue Mar 4, 2025 · 4 comments
Closed

Unable to list billing accounts using the Azure SDK for python #39933

juniinacio opened this issue Mar 4, 2025 · 4 comments
Assignees
Labels
Billing bug This issue requires a change to an existing behavior in the product in order to be resolved. customer-reported Issues that are reported by GitHub users external to the Azure organization. Mgmt This issue is related to a management-plane library. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team

Comments

@juniinacio
Copy link

juniinacio commented Mar 4, 2025

  • Package Name: azure-mgmt-billing
  • Package Version: 7.0.0
  • Operating System: Windows
  • Python Version: 3.11.7

Describe the bug
Unable to list billing accounts using the Azure SDK for python. When using the SDK to list billing accounts one has access to the SDK raises an exception:

azure.core.exceptions.DeserializationError: Unable to deserialize response data.

I suspect that the SDK is expecting the dates in the response to be in the ISO 8601 format but Azure response (in my case) with date in another format.

To Reproduce
Steps to reproduce the behavior:

  1. Create a simply Python script with the following content:
import logging
from azure.identity import DefaultAzureCredential
from azure.mgmt.billing import BillingManagementClient

logging.basicConfig(level=logging.DEBUG)

# Create a logger for the Azure SDK
logger = logging.getLogger("azure")
logger.setLevel(logging.DEBUG)


def main():
    client = BillingManagementClient(
        credential=DefaultAzureCredential(),
        subscription_id="XXXXXXXX",
    )

    accounts = client.billing_accounts.list()
    for account in accounts:
        print(account.as_dict())

if __name__ == "__main__":
    main()

  1. Login with Azure CLI with an account that has permissions to one or more billing accounts. (Alternatively one can also change the script to use ClientSecretCredential)

  2. Execute the script.

Expected behavior
The SDK should lists all billing accounts I have access to.

Screenshots
Error details:

azure.core.exceptions.DeserializationError: Unable to deserialize response data. Data: [{'id': '/providers/Microsoft.Billing/billingAccounts/XXXXXXXX', 'name': 'XXXXXXXX', 'properties': {'accountStatus': 'Extended', 'accountType': 'Enterprise', 'accountSubType': 'Other', 'agreementType': 'EnterpriseAgreement', 'displayName': 'XXXXXXXX', 'enrollmentDetails': {'startDate': '3/31/2015 12:00:00 AM +00:00', 'endDate': '3/31/2018 12:00:00 AM +00:00', 'currency': 'EUR', 'channel': 'EaDirect', 'language': 'nl', 'countryCode': 'NL ', 'billingCycle': 'Quarterly', 'extendedTermOption': 'Other', 'supportLevel': 'Other'}, 'hasReadAccess': True, 'soldTo': {'companyName': 'XXXXX', 'country': 'NL ', 'isValidAddress': True}}, 'type': 'Microsoft.Billing/billingAccounts'}, {'id': '/providers/Microsoft.Billing/billingAccounts/bbbbbbbbbb', 'name': 'bbbbbbbbbb', 'properties': {'accountStatus': 'Active', 'accountType': 'Individual', 'accountSubType': 'Other', 'agreementType': 'MicrosoftOnlineServicesProgram', 'displayName': 'bbbbb', 'hasReadAccess': True, 'notificationEmailAddress': '[email protected]', 'primaryBillingTenantId': 'bbbbbb', 'soldTo': {'addressLine3': '', 'companyName': 'bbbbb', 'country': 'NL', 'firstName': 'bbbb', 'lastName': 'bbbbb', 'phoneNumber': 'bbbbb', 'isValidAddress': True}}, 'type': 'Microsoft.Billing/billingAccounts'}], [BillingAccount]

Additional context
None.

@juniinacio juniinacio changed the title Unable to list storage accounts using the Azure SDK for python Unable to list billing accounts using the Azure SDK for python Mar 4, 2025
@github-actions github-actions bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Mar 4, 2025
@xiangyan99 xiangyan99 added bug This issue requires a change to an existing behavior in the product in order to be resolved. Billing Mgmt This issue is related to a management-plane library. and removed question The issue doesn't require a change to the product in order to be resolved. Most issues start as that needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. labels Mar 4, 2025
@github-actions github-actions bot added the needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team label Mar 4, 2025
@ChenxiJiang333
Copy link
Member

Hi @juniinacio, could you share the log of this script (following https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/debug_guide.md)? We need to see how the date shows like in the service response.

@juniinacio
Copy link
Author

juniinacio commented Mar 5, 2025

@ChenxiJiang333 You can already see the date in the issue under Screenshots section (I have make it bold, it is the start and end dates for the enrollment details of the billing account). But in either case I have also added the logger configuration you requested and I don't see a difference in what I have already provided and what the new logger configuration gives. But in either case I have added the full log trace:

azure.identity._exceptions.CredentialUnavailableError: Failed to invoke PowerShell. Enable debug logging for additional information.
2025-03-05 07:27:56,352 - azure.identity._credentials.azd_cli - DEBUG - Executing subprocess with the following arguments ['C:\\Users\\Juni\\AppData\\Local\\Programs\\Azure Dev CLI\\azd.EXE', 'auth', 'token', '--output', 'json', '--scope', 'https://management.azure.com/.default']
2025-03-05 07:27:58,236 - azure.identity._internal.decorators - DEBUG - AzureDeveloperCliCredential.get_token_info succeeded
2025-03-05 07:27:58,237 - azure.identity._internal.decorators - DEBUG - [Authenticated account] Client ID: 00000000-0000-0000-0000-000000000000. Tenant ID: 00000000-0000-0000-0000-000000000000. User Principal Name: [email protected]. Object ID (user): [email protected]
2025-03-05 07:27:58,237 - azure.identity._credentials.chained - INFO - DefaultAzureCredential acquired a token from AzureDeveloperCliCredential
2025-03-05 07:27:58,238 - azure.core.pipeline.policies.http_logging_policy - INFO - Request URL: 'https://management.azure.com/providers/Microsoft.Billing/billingAccounts?includeAll=REDACTED&includeAllWithoutBillingProfiles=REDACTED&includeDeleted=REDACTED&includePendingAgreement=REDACTED&includeResellee=REDACTED&api-version=REDACTED&expand=REDACTED'
Request method: 'GET'
Request headers:
    'Accept': 'application/json'
    'x-ms-client-request-id': 'f2dcc0af-f98a-11ef-b867-60452e8a9577'
    'User-Agent': 'azsdk-python-mgmt-billing/7.0.0 Python/3.11.7 (Windows-10-10.0.26100-SP0)'
    'Authorization': 'REDACTED'
No body was attached to the request
2025-03-05 07:27:58,241 - urllib3.connectionpool - DEBUG - Starting new HTTPS connection (1): management.azure.com:443
2025-03-05 07:27:59,123 - urllib3.connectionpool - DEBUG - https://management.azure.com:443 "GET /providers/Microsoft.Billing/billingAccounts?includeAll=false&includeAllWithoutBillingProfiles=false&includeDeleted=false&includePendingAgreement=false&includeResellee=false&api-version=2024-04-01&expand=soldTo HTTP/1.1" 200 1301
2025-03-05 07:27:59,136 - azure.core.pipeline.policies.http_logging_policy - INFO - Response status: 200
Response headers:
    'Cache-Control': 'no-cache'
    'Pragma': 'no-cache'
    'Content-Length': '1301'
    'Content-Type': 'application/json; charset=utf-8'
    'Expires': '-1'
    'Vary': 'REDACTED'
    'x-ms-ratelimit-remaining-tenant-reads': '249'
    'Strict-Transport-Security': 'REDACTED'
    'x-ms-service-version': 'REDACTED'
    'api-supported-versions': 'REDACTED'
    'X-Frame-Options': 'REDACTED'
    'x-ms-request-id': '00000000-0000-0000-0000-000000000000'
    'x-ms-correlation-request-id': 'REDACTED'
    'x-ms-routing-request-id': 'REDACTED'
    'X-Content-Type-Options': 'REDACTED'
    'X-Cache': 'REDACTED'
    'X-MSEdge-Ref': 'Ref A: 0A7D25A1E7254CC6B73DF9D7A859E135 Ref B: AMS231032608023 Ref C: 2025-03-05T06:27:59Z'
    'Date': 'Wed, 05 Mar 2025 06:27:59 GMT'
Traceback (most recent call last):
  File "C:\Users\Juni\Desktop\python-testing\.venv\Lib\site-packages\azure\mgmt\billing\_serialization.py", line 1959, in deserialize_iso
    raise ValueError("Invalid datetime string: " + attr)
ValueError: Invalid datetime string: 3/31/2015 12:00:00 AM +00:00

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\Juni\Desktop\python-testing\.venv\Lib\site-packages\azure\mgmt\billing\_serialization.py", line 1633, in deserialize_data
    data_val = self.deserialize_type[data_type](data)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Juni\Desktop\python-testing\.venv\Lib\site-packages\azure\mgmt\billing\_serialization.py", line 1978, in deserialize_iso
    raise DeserializationError(msg) from err
azure.core.exceptions.DeserializationError: Cannot deserialize datetime object.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\Juni\Desktop\python-testing\.venv\Lib\site-packages\azure\mgmt\billing\_serialization.py", line 1638, in deserialize_data
    return self.deserialize_type[iter_type](data, data_type[1:-1])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Juni\Desktop\python-testing\.venv\Lib\site-packages\azure\mgmt\billing\_serialization.py", line 1666, in deserialize_iter
    return [self.deserialize_data(a, iter_type) for a in attr]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Juni\Desktop\python-testing\.venv\Lib\site-packages\azure\mgmt\billing\_serialization.py", line 1666, in <listcomp>
    return [self.deserialize_data(a, iter_type) for a in attr]
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Juni\Desktop\python-testing\.venv\Lib\site-packages\azure\mgmt\billing\_serialization.py", line 1651, in deserialize_data
    return self._deserialize(obj_type, data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Juni\Desktop\python-testing\.venv\Lib\site-packages\azure\mgmt\billing\_serialization.py", line 1474, in _deserialize
    value = self.deserialize_data(raw_value, attr_desc["type"])
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Juni\Desktop\python-testing\.venv\Lib\site-packages\azure\mgmt\billing\_serialization.py", line 1651, in deserialize_data
    return self._deserialize(obj_type, data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Juni\Desktop\python-testing\.venv\Lib\site-packages\azure\mgmt\billing\_serialization.py", line 1474, in _deserialize
    value = self.deserialize_data(raw_value, attr_desc["type"])
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Juni\Desktop\python-testing\.venv\Lib\site-packages\azure\mgmt\billing\_serialization.py", line 1651, in deserialize_data
    return self._deserialize(obj_type, data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Juni\Desktop\python-testing\.venv\Lib\site-packages\azure\mgmt\billing\_serialization.py", line 1474, in _deserialize
    value = self.deserialize_data(raw_value, attr_desc["type"])
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Juni\Desktop\python-testing\.venv\Lib\site-packages\azure\mgmt\billing\_serialization.py", line 1649, in deserialize_data
    raise DeserializationError(msg) from err
azure.core.exceptions.DeserializationError: Unable to deserialize response data. Data: 3/31/2015 12:00:00 AM +00:00, iso-8601

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\Juni\Desktop\python-testing\billing_accounts_list.py", line 30, in <module>
    main()
  File "C:\Users\Juni\Desktop\python-testing\billing_accounts_list.py", line 25, in main
    for account in accounts:
  File "C:\Users\Juni\Desktop\python-testing\.venv\Lib\site-packages\azure\core\paging.py", line 123, in __next__
    return next(self._page_iterator)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Juni\Desktop\python-testing\.venv\Lib\site-packages\azure\core\paging.py", line 83, in __next__
    self.continuation_token, self._current_page = self._extract_data(self._response)
                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Juni\Desktop\python-testing\.venv\Lib\site-packages\azure\mgmt\billing\operations\_billing_accounts_operations.py", line 1314, in extract_data
    deserialized = self._deserialize("BillingAccountListResult", pipeline_response)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Juni\Desktop\python-testing\.venv\Lib\site-packages\azure\mgmt\billing\_serialization.py", line 1408, in __call__
    return self._deserialize(target_obj, data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Juni\Desktop\python-testing\.venv\Lib\site-packages\azure\mgmt\billing\_serialization.py", line 1474, in _deserialize
    value = self.deserialize_data(raw_value, attr_desc["type"])
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Juni\Desktop\python-testing\.venv\Lib\site-packages\azure\mgmt\billing\_serialization.py", line 1649, in deserialize_data
    raise DeserializationError(msg) from err
azure.core.exceptions.DeserializationError: Unable to deserialize response data. Data: [{'id': '/providers/Microsoft.Billing/billingAccounts/00000000', 'name': '00000000', 'properties': {'accountStatus': 'Extended', 'accountType': 'Enterprise', 'accountSubType': 'Other', 'agreementType': 'EnterpriseAgreement', 'displayName': 'Foo Bar B.V.', 'enrollmentDetails': {'startDate': '3/31/2015 12:00:00 AM +00:00', 'endDate': '3/31/2018 12:00:00 AM +00:00', 'currency': 'EUR', 'channel': 'EaDirect', 'language': 'nl', 'countryCode': 'NL ', 'billingCycle': 'Quarterly', 'extendedTermOption': 'Other', 'supportLevel': 'Other'}, 'hasReadAccess': True, 'soldTo': {'companyName': 'Foo Bar B.V.', 'country': 'NL ', 'isValidAddress': True}}, 'type': 'Microsoft.Billing/billingAccounts'}, {'id': '/providers/Microsoft.Billing/billingAccounts/00000000-0000-0000-0000-000000000000', 'name': '00000000-0000-0000-0000-000000000000', 'properties': {'accountStatus': 'Active', 'accountType': 'Individual', 'accountSubType': 'Other', 'agreementType': 'MicrosoftOnlineServicesProgram', 'displayName': 'Foo Bar', 'hasReadAccess': True, 'notificationEmailAddress': '[email protected]', 'primaryBillingTenantId': '00000000-0000-0000-0000-000000000000', 'soldTo': {'addressLine3': '', 'companyName': 'Foo Bar', 'country': 'NL', 'firstName': 'Foo', 'lastName': 'Bar', 'phoneNumber': '000000000', 'isValidAddress': True}}, 'type': 'Microsoft.Billing/billingAccounts'}], [BillingAccount]

@ChenxiJiang333
Copy link
Member

@juniinacio my bad for not noticing that. Since it's a service behavior that sdk team cannot make any change on it, I have opened an issue to get service attention. Please follow Azure/azure-rest-api-specs#33009 to get support.

@juniinacio
Copy link
Author

@ChenxiJiang333 thanks for your reply, I will keep an eye on that thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Billing bug This issue requires a change to an existing behavior in the product in order to be resolved. customer-reported Issues that are reported by GitHub users external to the Azure organization. Mgmt This issue is related to a management-plane library. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team
Projects
None yet
Development

No branches or pull requests

4 participants