Skip to content

[Issue] Failed with credential exception when debug API locally (Todo Python Mongo) #262

Description

@Flanker32

Output from azd version
Run azd version and copy and paste the output here:

azd version 0.0.1-beta.1689529 (commit 72c893853d9ae0e63c723a17a84771b7407ace1e)

Describe the bug
Description of issue you're seeing...
Following VSCode quick start document with python project (Todo Python Mongo), in Debug API section, program failed with exception

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.
        VisualStudioCodeCredential: Azure Active Directory error '(invalid_grant) AADSTS700082: The refresh token has expired due to inactivity. The token was issued on 2021-12-13T08:20:41.3682934Z 
and was inactive for 90.00:00:00.
Trace ID: c99bcfa3-62aa-41b2-9253-7f1011c34200
Correlation ID: 70bc9055-6db6-4f59-a89b-8b915b43a1fa
Timestamp: 2022-07-07 07:57:26Z'
Content: {"error":"invalid_grant","error_description":"AADSTS700082: The refresh token has expired due to inactivity. The token was issued on 2021-12-13T08:20:41.3682934Z and was inactive for 90.00:00:00.\r\nTrace ID: c99bcfa3-62aa-41b2-9253-7f1011c34200\r\nCorrelation ID: 70bc9055-6db6-4f59-a89b-8b915b43a1fa\r\nTimestamp: 2022-07-07 07:57:26Z","error_codes":[700082],"timestamp":"2022-07-07 07:57:26Z","trace_id":"c99bcfa3-62aa-41b2-9253-7f1011c34200","correlation_id":"70bc9055-6db6-4f59-a89b-8b915b43a1fa","error_uri":"https://login.microsoftonline.com/error?code=700082"}
To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/python/identity/defaultazurecredential/troubleshoot.
Process SpawnProcess-1:
Traceback (most recent call last):
  File "C:\Python39\lib\multiprocessing\process.py", line 315, in _bootstrap
    self.run()
  File "C:\Python39\lib\multiprocessing\process.py", line 108, in run       
    self._target(*self._args, **self._kwargs)
  File "D:\BugBash-ADC\Test-Python\src\api\api_env\lib\site-packages\uvicorn\subprocess.py", line 76, in subprocess_started
    target(sockets=sockets)
  File "D:\BugBash-ADC\Test-Python\src\api\api_env\lib\site-packages\uvicorn\server.py", line 60, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "C:\Python39\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:\Python39\lib\asyncio\base_events.py", line 642, in run_until_complete
    return future.result()
  File "D:\BugBash-ADC\Test-Python\src\api\api_env\lib\site-packages\uvicorn\server.py", line 67, in serve
    config.load()
  File "D:\BugBash-ADC\Test-Python\src\api\api_env\lib\site-packages\uvicorn\config.py", line 458, in load
    self.loaded_app = import_from_string(self.app)
  File "D:\BugBash-ADC\Test-Python\src\api\api_env\lib\site-packages\uvicorn\importer.py", line 21, in import_from_string
    module = importlib.import_module(module_str)
  File "C:\Python39\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "D:\BugBash-ADC\Test-Python\src\api\.\todo\app.py", line 18, in <module>
    settings = Settings()
  File "D:\BugBash-ADC\Test-Python\src\api\.\todo\models.py", line 23, in __init__
    for secret in keyvault_client.list_properties_of_secrets():
  File "D:\BugBash-ADC\Test-Python\src\api\api_env\lib\site-packages\azure\core\paging.py", line 128, in __next__
    return next(self._page_iterator)
  File "D:\BugBash-ADC\Test-Python\src\api\api_env\lib\site-packages\azure\core\paging.py", line 76, in __next__
    self._response = self._get_next(self.continuation_token)
  File "D:\BugBash-ADC\Test-Python\src\api\api_env\lib\site-packages\azure\keyvault\secrets\_generated\v7_3\operations\_key_vault_client_operations.py", line 790, in get_next
    pipeline_response = self._client._pipeline.run(  # pylint: disable=protected-access
  File "D:\BugBash-ADC\Test-Python\src\api\api_env\lib\site-packages\azure\core\pipeline\_base.py", line 211, in run
    return first_node.send(pipeline_request)  # type: ignore
  File "D:\BugBash-ADC\Test-Python\src\api\api_env\lib\site-packages\azure\core\pipeline\_base.py", line 71, in send
    response = self.next.send(request)
  File "D:\BugBash-ADC\Test-Python\src\api\api_env\lib\site-packages\azure\core\pipeline\_base.py", line 71, in send
    response = self.next.send(request)
  File "D:\BugBash-ADC\Test-Python\src\api\api_env\lib\site-packages\azure\core\pipeline\_base.py", line 71, in send
    response = self.next.send(request)
  [Previous line repeated 2 more times]
  File "D:\BugBash-ADC\Test-Python\src\api\api_env\lib\site-packages\azure\core\pipeline\policies\_redirect.py", line 158, in send
    response = self.next.send(request)
  File "D:\BugBash-ADC\Test-Python\src\api\api_env\lib\site-packages\azure\core\pipeline\policies\_retry.py", line 446, in send
    response = self.next.send(request)
  File "D:\BugBash-ADC\Test-Python\src\api\api_env\lib\site-packages\azure\core\pipeline\policies\_authentication.py", line 128, in send
    request_authorized = self.on_challenge(request, response)
  File "D:\BugBash-ADC\Test-Python\src\api\api_env\lib\site-packages\azure\keyvault\secrets\_shared\challenge_auth_policy.py", line 102, in on_challenge
    self.authorize_request(request, scope, tenant_id=challenge.tenant_id)
  File "D:\BugBash-ADC\Test-Python\src\api\api_env\lib\site-packages\azure\core\pipeline\policies\_authentication.py", line 107, in authorize_request
    self._token = self._credential.get_token(*scopes, **kwargs)
  File "D:\BugBash-ADC\Test-Python\src\api\api_env\lib\site-packages\azure\identity\_credentials\default.py", line 175, in get_token
    return super(DefaultAzureCredential, self).get_token(*scopes, **kwargs)
  File "D:\BugBash-ADC\Test-Python\src\api\api_env\lib\site-packages\azure\identity\_credentials\chained.py", line 108, 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: ManagedIdentityCredential authentication unavailable, no response from the IMDS endpoint.
        SharedTokenCacheCredential: SharedTokenCacheCredential authentication unavailable. No accounts were found in the cache.
        VisualStudioCodeCredential: Azure Active Directory error '(invalid_grant) AADSTS700082: The refresh token has expired due to inactivity. The token was issued on 2021-12-13T08:20:41.3682934Z and was inactive for 90.00:00:00.
and was inactive for 90.00:00:00.
Trace ID: c99bcfa3-62aa-41b2-9253-7f1011c34200
Correlation ID: 70bc9055-6db6-4f59-a89b-8b915b43a1fa
Timestamp: 2022-07-07 07:57:26Z'                                                                                                                                                                      00:00.\r\nTrace ID: c99bcfa3-62aa-41b2-9253-7f
Content: {"error":"invalid_grant","error_description":"AADSTS700082: The refresh token has expired due to inactivity. The token was issued on 2021-12-13T08:20:41.3682934Z and was inactive for 90.00:f1011c34200","correlation_id":"70bc9055-6db6-400:00.\r\nTrace ID: c99bcfa3-62aa-41b2-9253-7f1011c34200\r\nCorrelation ID: 70bc9055-6db6-4f59-a89b-8b915b43a1fa\r\nTimestamp: 2022-07-07 07:57:26Z","error_codes":[700082],"timestamp":"2022-07-07 07:57:26Z","trace_id":"c99bcfa3-62aa-41b2-9253-7f1011c34200","correlation_id":"70bc9055-6db6-4f59-a89b-8b915b43a1fa","error_uri":"https://login.microsoftonline.com/error?code=700082"}
To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/python/identity/defaultazurecredential/troubleshoot.
  • Tried to sign-out and sign in again in VSCode, the issue still reproduced
  • Tried demo project for node js, could works well in local development
  • Command Azure Developer: provision Azure resources runs successfully

To Reproduce

  • Install the latest ci and vscode extension
  • Run VSCode command Azure Developer: init and select Azure-Samples/todo-python-mongo
  • Run VSCode command Azure Developer: provision Azure resources
  • In VSCode Activity Bar, select Run and Debug, the Debug API debug configuration, and the Start Debugging arrow

Expected behavior
Could run and debug project locally, maybe we could use the same credential in step provision Azure resources.

Environment
Information on your environment:
* Language name and version : Python 3.9.7
* IDE and version : [e.g. Visual Studio 16.3] Visual Studio Code 1.68.1

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions