diff --git a/sdk/identity/azure-identity/CHANGELOG.md b/sdk/identity/azure-identity/CHANGELOG.md index bd3a14d3805d..8d039fd5c7c3 100644 --- a/sdk/identity/azure-identity/CHANGELOG.md +++ b/sdk/identity/azure-identity/CHANGELOG.md @@ -1,6 +1,9 @@ # Release History ## 1.4.0b6 (Unreleased) +- `AzureCliCredential` no longer raises an exception due to unexpected output + from the CLI when run by PyCharm (thanks @NVolcz) + ([#11362](https://github.com/Azure/azure-sdk-for-python/pull/11362)) - Upgraded minimum `msal` version to 1.3.0 - The async `AzureCliCredential` correctly invokes `/bin/sh` ([#12048](https://github.com/Azure/azure-sdk-for-python/issues/12048)) diff --git a/sdk/identity/azure-identity/azure/identity/_credentials/azure_cli.py b/sdk/identity/azure-identity/azure/identity/_credentials/azure_cli.py index 07687f8d32c1..c5fe99a1119c 100644 --- a/sdk/identity/azure-identity/azure/identity/_credentials/azure_cli.py +++ b/sdk/identity/azure-identity/azure/identity/_credentials/azure_cli.py @@ -104,7 +104,12 @@ def _run_command(command): try: working_directory = get_safe_working_dir() - kwargs = {"stderr": subprocess.STDOUT, "cwd": working_directory, "universal_newlines": True} + kwargs = { + "stderr": subprocess.STDOUT, + "cwd": working_directory, + "universal_newlines": True, + "env": dict(os.environ, AZURE_CORE_NO_COLOR="true"), + } if platform.python_version() >= "3.3": kwargs["timeout"] = 10 diff --git a/sdk/identity/azure-identity/azure/identity/aio/_credentials/azure_cli.py b/sdk/identity/azure-identity/azure/identity/aio/_credentials/azure_cli.py index a562a7831b9f..56c025680db3 100644 --- a/sdk/identity/azure-identity/azure/identity/aio/_credentials/azure_cli.py +++ b/sdk/identity/azure-identity/azure/identity/aio/_credentials/azure_cli.py @@ -4,6 +4,7 @@ # ------------------------------------ import asyncio import sys +import os from azure.core.exceptions import ClientAuthenticationError from .._credentials.base import AsyncCredentialBase @@ -68,7 +69,11 @@ async def _run_command(command): try: proc = await asyncio.create_subprocess_exec( - *args, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.STDOUT, cwd=working_directory + *args, + stdout=asyncio.subprocess.PIPE, + stderr=asyncio.subprocess.STDOUT, + cwd=working_directory, + env=dict(os.environ, AZURE_CORE_NO_COLOR="true") ) except OSError as ex: # failed to execute 'cmd' or '/bin/sh'; CLI may or may not be installed