azure-sdk-for-python
azure-sdk-for-python copied to clipboard
azure.data.tables: 'ClientAuthenticationError' object has no attribute 'error_code'
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())
Thanks for the feedback, we’ll investigate asap.
@YalinLi0312 Seems like we made the assumption here that HttpResponseError must have error_code.
Could you help to take a look?
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.
Hi @natbprice , we'll prepare a release to include the bug fix. Thank you!
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.