azure-sdk-for-python icon indicating copy to clipboard operation
azure-sdk-for-python copied to clipboard

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

Open natbprice opened this issue 2 years ago • 2 comments

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())

natbprice avatar Nov 09 '22 22:11 natbprice

Thanks for the feedback, we’ll investigate asap.

xiangyan99 avatar Nov 10 '22 16:11 xiangyan99

@YalinLi0312 Seems like we made the assumption here that HttpResponseError must have error_code.

Could you help to take a look?

xiangyan99 avatar Nov 10 '22 17:11 xiangyan99

Hi @natbprice. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text "/unresolve" to remove the "issue-addressed" label and continue the conversation.

github-actions[bot] avatar May 31 '23 22:05 github-actions[bot]

Hi @natbprice , we'll prepare a release to include the bug fix. Thank you!

YalinLi0312 avatar May 31 '23 22:05 YalinLi0312

Hi @natbprice, since you haven’t asked that we /unresolve the issue, we’ll close this out. If you believe further discussion is needed, please add a comment /unresolve to reopen the issue.

github-actions[bot] avatar Jun 08 '23 04:06 github-actions[bot]