Azure / Azure/azure-cli

Consider use UTF-8 by default for Azure CLI

Open
#28,497 15 comments 3 reactions 1 assignee Assigned to @jiasli View on GitHub
Account act-identity-squad Auto-Assign Azure CLI Team customer-reported question
Dominant language
Python
Stars
4.6k
Forks
3.5k
Avg merge
3d 2h
Merged PRs (30d)
60

Description

### Describe the bug

I was reported a bug on StackOverflow: https://stackoverflow.com/q/78008939/910074

When I have to use `UTF-8` for my default console output encoding (`[Console]::OutputEncoding`), the Azure CLI unable to handle Chinese characters because Encoding issue. It cause either Chinese chars missing or produce messy code.

### Related command

`$(az account list -o json)`

`az account list -o json | jq '.'`

### Errors

![image](https://github.com/Azure/azure-cli/assets/88981/2af77491-2e37-44f8-97e2-3426078f6e46)

### Issue script & Debug output

It's an encoding issue.

### Expected behavior

I expected Azure CLI can handle Chinese characters correctly.

### Environment Summary

azure-cli 2.57.0

core 2.57.0
telemetry 1.1.0

Extensions:
account 0.2.3
azure-devops 0.25.0
front-door 1.0.16
interactive 0.4.5
k8s-extension 1.2.4
managementpartner 0.1.3

Dependencies:
msal 1.26.0
azure-mgmt-resource 23.1.0b2

Python location 'C:\Program Files\Microsoft SDKs\Azure\CLI2\python.exe'
Extensions directory 'C:\Users\wakau\.azure\cliextensions'

Python (Windows) 3.11.7 (tags/v3.11.7:fa7a6f2, Dec 4 2023, 19:24:49) [MSC v.1937 64 bit (AMD64)]

Legal docs and information: aka.ms/AzureCliLegal

Your CLI is up-to-date.

### Additional context

I have a workaround by now. Just edit `C:\Program Files\Microsoft SDKs\Azure\CLI2\wbin\az.cmd` file. Add `-X utf8` to the python arguments.

```bat
::
:: Microsoft Azure CLI - Windows Installer - Author file components script
:: Copyright (C) Microsoft Corporation. All Rights Reserved.
::

@IF EXIST "%~dp0\..\python.exe" (
SET AZ_INSTALLER=MSI
"%~dp0\..\python.exe" -X utf8 -IBm azure.cli %*
) ELSE (
echo Failed to load python executable.
exit /b 1
)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.