Skip to content

azure.data.tables: 'ClientAuthenticationError' object has no attribute 'error_code' #27410

@natbprice

Description

@natbprice

Packages: azure-data-tables==12.4.1, azure-identity==1.12.0
Operating System: Windows 10
Python Version: 3.10.4

Describe the bug
When DefaultAzureCredential() fails to retrieve a token with azure.data.tables.aio.TableServiceClient().create_table_if_not_exists() the error does not appear to be handled properly.

Observed error message:
'ClientAuthenticationError' object has no attribute 'error_code'

Expected error message (or similar):

azure.core.exceptions.ClientAuthenticationError: ChainedTokenCredential failed to retrieve a token from the included credentials.
Attempted credentials:
EnvironmentCredential: EnvironmentCredential authentication unavailable. Environment variables are not fully configured.
Visit https://aka.ms/azsdk/python/identity/environmentcredential/troubleshoot to troubleshoot.this issue.
ManagedIdentityCredential: ManagedIdentityCredential authentication unavailable, no response from the IMDS endpoint.
VisualStudioCodeCredential: Failed to get Azure user details from Visual Studio Code.
AzureCliCredential: Failed to execute 'cmd'
AzurePowerShellCredential: Failed to execute "cmd".
To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/python/identity/powershellcredential/troubleshoot.

Reproducible Example:
Run code in environment where DefaultAzureCredential() will fail.

import asyncio

class SampleTablesQuery(object):
    def __init__(self):
        self.account = "myaccount"
        self.table = "TestInsert"

    async def test_create_table(self):
        from azure.identity.aio import DefaultAzureCredential
        from azure.data.tables.aio import TableServiceClient
        credential = DefaultAzureCredential(
            exclude_shared_token_cache_credential=True,
            exclude_powershell_credential=True,
            exclude_cli_credential=True)
        async with credential:
            table_service_client = TableServiceClient(
                endpoint="https://{}.table.core.windows.net/".format(
                    self.account),
                credential=credential)
            async with table_service_client:
                await table_service_client.create_table_if_not_exists(table_name=self.table)


async def main():
    stq = SampleTablesQuery()
    try:
        await stq.test_create_table()
    except Exception as e:
        print(e)

if __name__ == "__main__":
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
    asyncio.run(main())

Metadata

Metadata

Labels

ClientThis issue points to a problem in the data-plane of the library.Tablesissue-addressedWorkflow: The Azure SDK team believes it to be addressed and ready to close.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions