azure-search-openai-demo icon indicating copy to clipboard operation
azure-search-openai-demo copied to clipboard

DefaultAzureCredential failed to retrieve a token from the included credentials.

Open Ishita-Singh1808 opened this issue 1 year ago • 7 comments

I am trying to run the below code : results = [doc[KB_FIELDS_SOURCEPAGE] + ": " + doc[KB_FIELDS_CONTENT].replace("\n", "").replace("\r", "") for doc in r]

and getting the below error:

Searching: Does my plan cover annual eye exams?
-------------------
DefaultAzureCredential 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.
	SharedTokenCacheCredential: SharedTokenCacheCredential authentication unavailable. No accounts were found in the cache.
	AzureCliCredential: Azure CLI not found on path
	AzurePowerShellCredential: Az.Account module >= 2.2.0 is not installed
To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/python/identity/defaultazurecredential/troubleshoot.


Output exceeds the [size limit](command:workbench.action.openSettings?%5B%22notebook.output.textLineLimit%22%5D). Open the full output data [in a text editor](command:workbench.action.openLargeOutput?d3e20780-6c64-40dc-80ae-0e2a1f90077e)
---------------------------------------------------------------------------
ClientAuthenticationError                 Traceback (most recent call last)
Cell In[7], line 29
     21 filter = "category ne '{}'".format(exclude_category.replace("'", "''")) if exclude_category else None
     22 r = search_client.search(search, 
     23                          filter=filter,
     24                          query_type=QueryType.SEMANTIC, 
   (...)
     27                          semantic_configuration_name="default", 
     28                          top=3)
---> 29 results = [doc[KB_FIELDS_SOURCEPAGE] + ": " + doc[KB_FIELDS_CONTENT].replace("\n", "").replace("\r", "") for doc in r]
     30 content = "\n".join(results)
     32 prompt = prompt_prefix.format(sources=content) + prompt_history + user_input + turn_suffix


Cell In[7], line 29, in (.0)
     21 filter = "category ne '{}'".format(exclude_category.replace("'", "''")) if exclude_category else None
     22 r = search_client.search(search, 
     23                          filter=filter,
     24                          query_type=QueryType.SEMANTIC, 
   (...)
     27                          semantic_configuration_name="default", 
     28                          top=3)
---> 29 results = [doc[KB_FIELDS_SOURCEPAGE] + ": " + doc[KB_FIELDS_CONTENT].replace("\n", "").replace("\r", "") for doc in r]
     30 content = "\n".join(results)
     32 prompt = prompt_prefix.format(sources=content) + prompt_history + user_input + turn_suffix
...
	ManagedIdentityCredential: ManagedIdentityCredential authentication unavailable, no response from the IMDS endpoint.
	SharedTokenCacheCredential: SharedTokenCacheCredential authentication unavailable. No accounts were found in the cache.
	AzureCliCredential: Azure CLI not found on path
	AzurePowerShellCredential: Az.Account module >= 2.2.0 is not installed
To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/python/identity/defaultazurecredential/troubleshoot

Ishita-Singh1808 avatar Apr 27 '23 12:04 Ishita-Singh1808

Any solution for this? I am getting the same error currently. I have also manually created the below fields related to fieldpages as it is not there previously, not sure if this is done right. image

navinsubramani avatar May 02 '23 21:05 navinsubramani

hey @navinsubramani , I think you have to update the SDK version for your application.

It looks like the DefaultAzureCredential (DAC) is not trying to fetch a token from azd

The log is listing what the DAC is trying:

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.
	SharedTokenCacheCredential: SharedTokenCacheCredential authentication unavailable. No accounts were found in the cache.
	AzureCliCredential: Azure CLI not found on path
	AzurePowerShellCredential: Az.Account module >= 2.2.0 is not installed

The requeriments from the python backend and the postprovision hook app are either azure-identity==1.13.0b3 or azure-identity==1.13.0b4 As that is where the DAC knows how to pull a token from azd

You might want to check what azure-identity version you are using. Did you maybe installed another version globally in your system?

vhvb1989 avatar May 02 '23 22:05 vhvb1989

Thanks @vhvb1989 . On further debugging, and use GPT I learnt that the Azure Active Directory based authentication is not supported for the Azure Cognitive Service. I am currently running the server locally, and so I have to use "AzureKeyCredentials" for the search service instead of "credentials". Found the documentation in the backend file did mention something like this as well. This is worked for me just now.

image

navinsubramani avatar May 03 '23 01:05 navinsubramani

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this issue will be closed.

github-actions[bot] avatar Dec 27 '23 01:12 github-actions[bot]

This is still a problem today. Who should update this and where?

    raise CredentialUnavailableError(AZ_ACCOUNT_NOT_INSTALLED)
azure.identity._exceptions.CredentialUnavailableError: Az.Account module >= 2.2.0 is not **installed**`
``

developer992 avatar Feb 01 '24 14:02 developer992

Are you logged in with azd auth login?

pamelafox avatar Feb 02 '24 00:02 pamelafox

I was, but i needed to add scope, it works now, thanks.

developer992 avatar Feb 02 '24 07:02 developer992