title: "Could not retrieve credential from local cache for service principal" when using Azure CLI 2.30.0 credentials in Python SDK on Azure Devops MS agent
body: <p>I an Azure Pipeline on a <strong>self-hosted agent</strong> I use this task</p>
  <pre class="lang-yaml prettyprint-override"><code>      - task: AzureCLI@2
          displayName: Azure CLI task with Python SDK
          inputs:
            azureSubscription: 'SUBSCRIPTION-SERVICE-CONNECTION'
            scriptType: bash
            scriptLocation: inlineScript
            inlineScript: |
              python ./magic-script.py
  
  </code></pre>
  <p>with that I am able to use the credentials to authenticate <strong>Azure Python SDK</strong>:</p>
  <pre class="lang-py prettyprint-override"><code>client = get_client_from_cli_profile(GraphRbacManagementClient)
  </code></pre>
  <p>When I transfer this process to a <strong>MS hosted agent</strong> I get this error:</p>
  <pre><code>  File &quot;/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/azure/common/client_factory.py&quot;, line 85, in get_client_from_cli_profile
      with_tenant=True,
    File &quot;/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/azure/common/credentials.py&quot;, line 98, in get_azure_cli_credentials
      cred, subscription_id, tenant_id = profile.get_login_credentials(resource=resource)
    File &quot;/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/azure/cli/core/_profile.py&quot;, line 335, in get_login_credentials
      credential = self._create_credential(account, client_id=client_id)
    File &quot;/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/azure/cli/core/_profile.py&quot;, line 592, in _create_credential
      return identity.get_service_principal_credential(username_or_sp_id)
    File &quot;/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/azure/cli/core/auth/identity.py&quot;, line 185, in get_service_principal_credential
      entry = self._msal_secret_store.load_entry(client_id, self.tenant_id)
    File &quot;/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/azure/cli/core/auth/identity.py&quot;, line 270, in load_entry
      .format(sp_id))
  knack.util.CLIError: Could not retrieve credential from local cache for service principal ***. Run `az login` for this service principal.
  </code></pre>
  <hr />
  <p>Based on this <a href="https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/identity/azure-identity/migration_guide.md#authenticating-through-the-azure-cli" rel="nofollow noreferrer">migration guide</a> I also tried <a href="https://docs.microsoft.com/de-de/azure/developer/python/azure-sdk-authenticate-development-environments#cli-based-authentication-with-azurecore-libraries" rel="nofollow noreferrer">AzureCliCredential</a> like</p>
  <pre><code>credential = AzureCliCredential()
  client = GraphRbacManagementClient(credential, os.environ[&quot;subscriptionId&quot;])   
  </code></pre>
  <p>which get's my script signed in - but when using <code>GraphRbacManagementClient</code> I get this error locally on my dev box and on the agent:</p>
  <pre><code>    root_group = [g for g in graph_client.groups.list(
    File &quot;C:\Python38\lib\site-packages\msrest\paging.py&quot;, line 143, in __next__
      self.advance_page()
    File &quot;C:\Python38\lib\site-packages\msrest\paging.py&quot;, line 129, in advance_page
      self._response = self._get_next(self.next_link)
    File &quot;C:\Python38\lib\site-packages\azure\graphrbac\operations\groups_operations.py&quot;, line 336, in internal_paging
      response = self._client.send(request, stream=False, **operation_config)
    File &quot;C:\Python38\lib\site-packages\msrest\service_client.py&quot;, line 336, in send
      pipeline_response = self.config.pipeline.run(request, **kwargs)
    File &quot;C:\Python38\lib\site-packages\msrest\pipeline\__init__.py&quot;, line 197, in run
      return first_node.send(pipeline_request, **kwargs)  # type: ignore
    File &quot;C:\Python38\lib\site-packages\msrest\pipeline\__init__.py&quot;, line 150, in send
      response = self.next.send(request, **kwargs)
    File &quot;C:\Python38\lib\site-packages\msrest\pipeline\requests.py&quot;, line 65, in send
      self._creds.signed_session(session)
  AttributeError: 'AzureCliCredential' object has no attribute 'signed_session'
  </code></pre>
  <p>For <code>StorageManagementClient</code> this works. Seems to be depending on the SDK client used.</p>