azure.core.exceptions.ClientAuthenticationError: Authentication failed: AADSTS500011处理方案

源代码:

ml_client = MLClient(
            credential=ClientSecretCredential(
                tenant_id=tenant_id,
                client_id=client_id,
                client_secret=client_secret,
                authority=AzureAuthorityHosts.AZURE_CHINA
            ),
            subscription_id=subscription_id,
            resource_group_name=resource_group,
            workspace_name=workspace
            )
View Code

报异常如下:

azure.core.exceptions.ClientAuthenticationError: Authentication failed: AADSTS500011: The resource principal named https://management.azure.com was not found in the tenant named Ecolab. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You might have sent your authentication request to the wrong tenant.

解决方案:

kwargs = {"cloud": "AzureChinaCloud"}
        ml_client = MLClient(
            credential=ClientSecretCredential(
                tenant_id=tenant_id,
                client_id=client_id,
                client_secret=client_secret,
                authority=AzureAuthorityHosts.AZURE_CHINA
            ),
            subscription_id=subscription_id,
            resource_group_name=resource_group,
            workspace_name=workspace,
            **kwargs
            )
View Code

究其原因是中国区的azure应该把https://management.azure.com改为https://management.chinacloudapi.cn即可。

posted on 2023-01-03 18:03  donchen-c  阅读(321)  评论(0编辑  收藏  举报