azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

az login --identity --debug fails with 'ascii' codec can't encode characters in position 16-24: ordinal not in range(128)

Open anhowe opened this issue 7 years ago • 5 comments

Describe the bug az login --identity --debug fails with 'ascii' codec can't encode characters in position 16-24: ordinal not in range(128)

Relevant parts of debug log from using --debug:

DEBUG: urllib3.connectionpool : Starting new HTTPS connection (1): management.azure.com:443
DEBUG: urllib3.connectionpool : https://management.azure.com:443 "GET /subscriptions?api-version=2016-06-01 HTTP/1.1" 200 None
ERROR: 'ascii' codec can't encode characters in position 16-24: ordinal not in range(128)
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/knack/cli.py", line 206, in invoke
    cmd_result = self.invocation.execute(args)
  File "/usr/local/lib/python2.7/dist-packages/azure/cli/core/commands/__init__.py", line 328, in execute
    raise ex
UnicodeEncodeError: 'ascii' codec can't encode characters in position 16-24: ordinal not in range(128)
INFO: Suppress exception There are no active accounts.

To Reproduce In the portal configure your subscription name to contain any non-ascii character. Next deploy an Ubuntu VM with managed identity, set appropriate role assignment to the VMs identity principalId, then run az login --identity from the VM.

Expected behavior az login --identity should complete without error and display the following message:

azureuser@vm-anhowe0404a:~$ az login --identity
[
  {
    "environmentName": "AzureCloud",
    "id": "YOUR_SUBSCRIPTION_ID",
    "isDefault": true,
    "name": "SUBSCRIPTION NAME WITH NON-ASCII CHARACTERS",
    "state": "Enabled",
    "tenantId": "YOUR_TENANT_ID",
    "user": {
      "assignedIdentityInfo": "MSI",
      "name": "systemAssignedIdentity",
      "type": "servicePrincipal"
    }
  }
]

anhowe avatar Apr 04 '19 11:04 anhowe

I can't reproduce even after renamed my subscription name to Japanese

yugangw-msft avatar Apr 05 '19 04:04 yugangw-msft

Howdy, @anhowe. How did you install the Azure CLI? I believe this issue should only repro in environments where the CLI is being executed by Python2.

marstr avatar Apr 05 '19 21:04 marstr

Hello Everybody,

I have the same issue, CLI was installed using both methods:

 https://docs.microsoft.com/ja-jp/cli/azure/install-azure-cli-linux?view=azure-cli-latest#install-or-update  https://docs.microsoft.com/ja-jp/cli/azure/install-azure-cli-yum?view=azure-cli-latest#install

CLI version is: azure-cli 2.0.60 And the debug of the command shows the same output as the posted by @anhowe

Is there any update with this?

Thanks,

bebarb avatar Apr 08 '19 17:04 bebarb

This issue also reproduced on my environment with Azure CLI 2.0.61. After changing my subscription name to mixture of alphabet and Japanese charcters, this issue has come to be observed.

As far as I've tested, this issue does not occur back in Azure CLI 2.0.42, in which version output of 'az login --identity' does not contain subscription name like below.

{ "environmentName": "AzureCloud", "id": "xxxxxxxxxxx", "isDefault": true, "name": "MSI", "state": "Enabled", "tenantId": "xxxxxxxxxxxxx", "user": { "name": "systemAssignedIdentity", "type": "servicePrincipal" } }

thiruma0203 avatar Apr 09 '19 11:04 thiruma0203

@thiruma0203, since 2.0.5x, we started to use the real subscription name on az login --identity, guess that caused the problem. This issue is specific on Python2, so what is your linux distro? Based on that we might be able to provide workaround in the meanwhile we are fixing this.

yugangw-msft avatar Apr 12 '19 01:04 yugangw-msft