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

DefaultAzureCredential - EnvironmentCredential error

Open stormrider88 opened this issue 1 year ago • 2 comments

This issue is for a: (mark with an x)

- [ x] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Followed the instructions, made "Local environment" and "Running locally". Running with ".start.ps1". At the "localhost" (http://127.0.0.1:50505/) the application starts, the GUI is displayed. The problem occurs when any question is asked in the chat. Then an error is displayed as a response: "Error: The app encountered an error processing your request. If you are an administrator of the app, view the full error in the logs. See aka.ms/appservice-logs for more information. Error type: <class 'azure.core.exceptions.ClientAuthenticationError'>".

image

We have checked many forums for the described error, unfortunately we have not found a solution, also we run out of ideas. We have the following credentials set:

PS E:_GIT\app\backend> azd env get-values
AZURE_ENV_NAME
AZURE_LOCATION
AZURE_OPENAI_CHATGPT_MODEL
AZURE_OPENAI_EMB_DEPLOYMENT
AZURE_PASSWORD
AZURE_RESOURCE_GROUP AZURE_SEARCH_INDEX AZURE_SEARCH_SERVICE
AZURE_STORAGE_ACCOUNT
AZURE_STORAGE_CONTAINER
AZURE_SUBSCRIPTION_ID
AZURE_TENANT_ID
AZURE_USERNAME

Also the "azd auth login" works fine, same the "PS E:_GIT\app\backend> az account get-access-token" returns a accessToken.

Any log messages given by the failure

File "E:_GIT\app\backend\backend_env\Lib\site-packages\azure\identity\aio_credentials\chained.py", line 107, in get_token raise ClientAuthenticationError(message=message) azure.core.exceptions.ClientAuthenticationError: 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: Unexpected response "{'error': 'service_unavailable', 'error_description': 'Service not available because the resource is not connected. Check Agent log for details.', 'error_codes': [503], 'timestamp': '2024-01-22 09:43:48.416177 +0100 CET m=+257232.170054701', 'trace_id': '', 'correlation_id': '0737f915-de76-4c3f-8fe0-1f28a25a6fbe'}" Content: {"error":"service_unavailable","error_description":"Service not available because the resource is not connected. Check Agent log for details.","error_codes":[503],"timestamp":"2024-01-22 09:43:48.416177 +0100 CET m=+257232.170054701","trace_id":"","correlat ion_id":"0737f915-de76-4c3f-8fe0-1f28a25a6fbe"} To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/python/identity/defaultazurecrede ntial/troubleshoot.

Expected/desired behavior

Not an error answer.

OS and Version?

Windows Server 2019 (on a VM).

azd version?

PS E:_GIT\app\backend> azd version azd version 1.5.1 (commit 3856d1e98281683b8d112e222c0a7c7b3e148e96)

Versions

Mention any other details that might be useful

If we deploy the app via azd deploy, the app works fine on the online cloud platform.

stormrider88 avatar Jan 22 '24 09:01 stormrider88

Also there is another question, if there is a way to debug (with breakspoints) the application when "Local environment" and "Running locally" is used. So we run the app in VS Code with ".start.ps1" from VS Code terminal.

stormrider88 avatar Jan 22 '24 09:01 stormrider88

Hello @stormrider88 ,

Default Azure Credential uses a chain of potential options to login. It seems like the option that is causing problems is ManagedIdentityCredential, which typically is only meant for running code in an Azure environment with Managed Identity enabled.

You can replace usage of DefaultAzureCredential() in this sample with DefaultAzureCredential(exclude_managed_identity_credential=True) and see if that helps, as documented here https://learn.microsoft.com/en-us/python/api/azure-identity/azure.identity.defaultazurecredential?view=azure-python

Regarding how to use breakpoints, the startup script launches a new process, so you'll need to attach to it. Please review https://code.visualstudio.com/docs/python/debugging for instructions on how to attach to another process for debugging.

I hope this helps

mattgotteiner avatar Jan 23 '24 16:01 mattgotteiner