Skip to content

Commit 73901fc

Browse files
committed
Fix Azure#26857: separate stdout from stderr in AzureCliCredential
1 parent f23a72b commit 73901fc

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

sdk/identity/azure-identity/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
### Bugs Fixed
1010

11+
* `AzureCliCredential` now works even when `az` prints warnings to stderr.
12+
1113
### Other Changes
1214

1315
## 1.12.0b2 (2022-10-11)

sdk/identity/azure-identity/azure/identity/_credentials/azure_cli.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def _run_command(command):
143143
working_directory = get_safe_working_dir()
144144

145145
kwargs = {
146-
"stderr": subprocess.STDOUT,
146+
"stderr": subprocess.PIPE,
147147
"cwd": working_directory,
148148
"universal_newlines": True,
149149
"env": dict(os.environ, AZURE_CORE_NO_COLOR="true"),
@@ -154,14 +154,14 @@ def _run_command(command):
154154
return subprocess.check_output(args, **kwargs)
155155
except subprocess.CalledProcessError as ex:
156156
# non-zero return from shell
157-
if ex.returncode == 127 or ex.output.startswith("'az' is not recognized"):
157+
if ex.returncode == 127 or ex.stderr.startswith("'az' is not recognized"):
158158
raise CredentialUnavailableError(message=CLI_NOT_FOUND)
159-
if "az login" in ex.output or "az account set" in ex.output:
159+
if "az login" in ex.stderr or "az account set" in ex.stderr:
160160
raise CredentialUnavailableError(message=NOT_LOGGED_IN)
161161

162162
# return code is from the CLI -> propagate its output
163-
if ex.output:
164-
message = sanitize_output(ex.output)
163+
if ex.stderr:
164+
message = sanitize_output(ex.stderr)
165165
else:
166166
message = "Failed to invoke Azure CLI"
167167
raise ClientAuthenticationError(message=message)

0 commit comments

Comments
 (0)