Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

az login results TypeError: can only concatenate str (not "NoneType") to str #29030

Open
ronttizz opened this issue May 27, 2024 · 11 comments · May be fixed by #29245
Open

az login results TypeError: can only concatenate str (not "NoneType") to str #29030

ronttizz opened this issue May 27, 2024 · 11 comments · May be fixed by #29245
Assignees
Labels
Account az login/account Auto-Assign Auto assign by bot Auto-Resolve Auto resolve by bot Azure CLI Team The command of the issue is owned by Azure CLI team customer-reported Issues that are reported by GitHub users external to the Azure organization. Possible-Solution question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Similar-Issue
Milestone

Comments

@ronttizz
Copy link

Describe the bug

Running az login will give TypeError: can only concatenate str (Not "NoneType") to str

Related command

az login

Errors

Retrieving tenants and subscriptions for the selection...
The command failed with an unexpected error. Here is the traceback:
can only concatenate str (not "NoneType") to str
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 664, in execute
    raise ex
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 731, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 701, in _run_job
    result = cmd_copy(params)
             ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 334, in __call__
    return self.handler(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
    return op(**command_args)
           ^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/command_modules/profile/custom.py", line 175, in login
    selected = SubscriptionSelector(subscriptions)()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/command_modules/profile/_subscription_selector.py", line 19, in __init__
    self._format_subscription_table()
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/command_modules/profile/_subscription_selector.py", line 52, in _format_subscription_table
    'Tenant': highlight_text(self._get_tenant_string(sub), is_default)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/command_modules/profile/_subscription_selector.py", line 31, in highlight_text
    return format_styled_text((Style.HIGHLIGHT, text)) if row_is_default else text
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/style.py", line 201, in format_styled_text
    formatted_parts.append(escape_seq + raw_text)
                           ~~~~~~~~~~~^~~~~~~~~~
TypeError: can only concatenate str (not "NoneType") to str
To check existing issues, please visit: https://github.com/Azure/azure-cli/issues

Issue script & Debug output

cli.azure.cli.core.azclierror: Traceback (most recent call last):
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 664, in execute
    raise ex
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 731, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 701, in _run_job
    result = cmd_copy(params)
             ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 334, in __call__
    return self.handler(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
    return op(**command_args)
           ^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/command_modules/profile/custom.py", line 175, in login
    selected = SubscriptionSelector(subscriptions)()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/command_modules/profile/_subscription_selector.py", line 19, in __init__
    self._format_subscription_table()
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/command_modules/profile/_subscription_selector.py", line 52, in _format_subscription_table
    'Tenant': highlight_text(self._get_tenant_string(sub), is_default)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/command_modules/profile/_subscription_selector.py", line 31, in highlight_text
    return format_styled_text((Style.HIGHLIGHT, text)) if row_is_default else text
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/style.py", line 201, in format_styled_text
    formatted_parts.append(escape_seq + raw_text)
                           ~~~~~~~~~~~^~~~~~~~~~
TypeError: can only concatenate str (not "NoneType") to str

cli.azure.cli.core.azclierror: The command failed with an unexpected error. Here is the traceback:
az_command_data_logger: The command failed with an unexpected error. Here is the traceback:
cli.azure.cli.core.azclierror: can only concatenate str (not "NoneType") to str
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 664, in execute
    raise ex
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 731, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 701, in _run_job
    result = cmd_copy(params)
             ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 334, in __call__
    return self.handler(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
    return op(**command_args)
           ^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/command_modules/profile/custom.py", line 175, in login
    selected = SubscriptionSelector(subscriptions)()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/command_modules/profile/_subscription_selector.py", line 19, in __init__
    self._format_subscription_table()
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/command_modules/profile/_subscription_selector.py", line 52, in _format_subscription_table
    'Tenant': highlight_text(self._get_tenant_string(sub), is_default)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/command_modules/profile/_subscription_selector.py", line 31, in highlight_text
    return format_styled_text((Style.HIGHLIGHT, text)) if row_is_default else text
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/style.py", line 201, in format_styled_text
    formatted_parts.append(escape_seq + raw_text)
                           ~~~~~~~~~~~^~~~~~~~~~
TypeError: can only concatenate str (not "NoneType") to str
az_command_data_logger: can only concatenate str (not "NoneType") to str
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 664, in execute
    raise ex
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 731, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 701, in _run_job
    result = cmd_copy(params)
             ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 334, in __call__
    return self.handler(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
    return op(**command_args)
           ^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/command_modules/profile/custom.py", line 175, in login
    selected = SubscriptionSelector(subscriptions)()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/command_modules/profile/_subscription_selector.py", line 19, in __init__
    self._format_subscription_table()
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/command_modules/profile/_subscription_selector.py", line 52, in _format_subscription_table
    'Tenant': highlight_text(self._get_tenant_string(sub), is_default)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/command_modules/profile/_subscription_selector.py", line 31, in highlight_text
    return format_styled_text((Style.HIGHLIGHT, text)) if row_is_default else text
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/style.py", line 201, in format_styled_text
    formatted_parts.append(escape_seq + raw_text)
                           ~~~~~~~~~~~^~~~~~~~~~
TypeError: can only concatenate str (not "NoneType") to str

Expected behavior

Show information on successful login

Environment Summary

azure-cli 2.61.0

core 2.61.0
telemetry 1.1.0

Dependencies:
msal 1.28.0
azure-mgmt-resource 23.1.1

Python location '/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/bin/python'
Extensions directory '/Users/x/.azure/cliextensions'

Python (Darwin) 3.11.9 (main, Apr 2 2024, 08:25:04) [Clang 15.0.0 (clang-1500.3.9.4)]

Legal docs and information: aka.ms/AzureCliLegal

Your CLI is up-to-date.

Additional context

No response

@ronttizz ronttizz added the bug This issue requires a change to an existing behavior in the product in order to be resolved. label May 27, 2024
Copy link

Hi @ronttizz
Find similar issue #16946.

Issue title A stacktrace with a disorienting message is shown for az apim api import
Create time 2021-02-16
Comment number 3

Possible solution:
The error message "can only concatenate str (not "NoneType") to str" is shown in both issues. In the existing issue, the error message is caused by not specifying the --specification-format parameter. Similarly, in the new issue, the error message is caused by a similar issue. The solution to the new issue is to specify the --specification-format parameter. You can check all the valid values for the --specification-format parameter by running "az apim api import -h".


Please confirm if this resolves your issue.

@yonzhan
Copy link
Collaborator

yonzhan commented May 27, 2024

Thank you for opening this issue, we will look into it.

@microsoft-github-policy-service microsoft-github-policy-service bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. Auto-Assign Auto assign by bot Account az login/account labels May 27, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added Azure CLI Team The command of the issue is owned by Azure CLI team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels May 27, 2024
@yonzhan yonzhan added this to the Backlog milestone May 27, 2024
@yonzhan yonzhan removed the bug This issue requires a change to an existing behavior in the product in order to be resolved. label May 27, 2024
@v-starodubov
Copy link

az config set core.login_experience_v2=off
Could help to resolve errors, until it's fixed.

@XhmikosR
Copy link

Confirmed that @v-starodubov's suggestion allows me to successfully login. Would be nice if this was fixed ASAP though since it's a serious regression.

@TheOnlyWei
Copy link

TheOnlyWei commented May 31, 2024

Same issue for our on-premises or hybrid environment. After the work-around for this different issue (#28997):

az account clear
az config set core.enable_broker_on_windows=false

I get the error in this GitHub issue above. However, I still end up being logged into the account. It just throws the error.

@jiasli
Copy link
Member

jiasli commented Jun 25, 2024

  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/command_modules/profile/_subscription_selector.py", line 52, in _format_subscription_table
    'Tenant': highlight_text(self._get_tenant_string(sub), is_default)

indicates self._get_tenant_string(sub) returned None:

@staticmethod
def _get_tenant_string(subscription):
try:
return subscription[_TENANT_DISPLAY_NAME]
except KeyError:
return subscription[_TENANT_ID]

According to the log provided by @m1iktea in #29241 (comment), https://management.azure.com/tenants?api-version=2022-12-01 API returned

cli.azure.cli.core.sdk.policies: {"value":[{"id":"/tenants/122f6959-7492-42d8-8cf5-f9233ac18c4f","tenantId":"122f6959-7492-42d8-8cf5-f9233ac18c4f","tenantCategory":"Home"}]}

displayName property is missing from the response JSON. This contradicts the ARM public document https://learn.microsoft.com/en-us/rest/api/resources/tenants/list?view=rest-resources-2022-12-01

@ronttizz, @v-starodubov, @XhmikosR, @TheOnlyWei, could you also check the --debug log and share the HTTP trace of https://management.azure.com/tenants?api-version=2022-12-01 API call?

@jiasli jiasli changed the title az login results TypeError az login results TypeError: can only concatenate str (not "NoneType") to str Jun 25, 2024
@jiasli jiasli linked a pull request Jun 25, 2024 that will close this issue
@v-starodubov
Copy link

@jiasli sure

cli.azure.cli.core.sdk.policies: Request URL: 'https://management.azure.com/tenants?api-version=2022-12-01'
...
cli.azure.cli.core.sdk.policies: Response content:
cli.azure.cli.core.sdk.policies: {"value":[{"id":"/tenants/d2012c1c-e56f-4ea4-ac1a-9d94f1c563c6","tenantId":"d2012c1c-e56f-4ea4-ac1a-9d94f1c563c6","tenantCategory":"Home"}]}

And error has dropped after the subscription request, may be related also 🤔

cli.azure.cli.core.sdk.policies: Request URL: 'https://management.azure.com/subscriptions?api-version=2022-12-01'
...
cli.azure.cli.core.sdk.policies: Response content:
cli.azure.cli.core.sdk.policies: {"value":[{"id":"/subscriptions/c8ed0cd4-dc57-41a9-ab2c-54beec7b9510","authorizationSource":"RoleBased","managedByTenants":[],"subscriptionId":"c8ed0cd4-dc57-41a9-ab2c-54beec7b9510","tenantId":"d2012c1c-e56f-4ea4-ac1a-9d94f1c563c6","displayName":"Microsoft Azure Sponsorship","state":"Enabled","subscriptionPolicies":{"locationPlacementId":"Public_2014-09-01","quotaId":"Sponsored_2016-01-01","spendingLimit":"Off"}}],"count":{"type":"Total","value":1}}

cli.azure.cli.core.azclierror: Traceback (most recent call last):
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 664, in execute
    raise ex
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 731, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 701, in _run_job
    result = cmd_copy(params)
             ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 334, in __call__
    return self.handler(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
    return op(**command_args)
           ^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/command_modules/profile/custom.py", line 175, in login
    selected = SubscriptionSelector(subscriptions)()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/command_modules/profile/_subscription_selector.py", line 19, in __init__
    self._format_subscription_table()
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/command_modules/profile/_subscription_selector.py", line 52, in _format_subscription_table
    'Tenant': highlight_text(self._get_tenant_string(sub), is_default)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/command_modules/profile/_subscription_selector.py", line 31, in highlight_text
    return format_styled_text((Style.HIGHLIGHT, text)) if row_is_default else text
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/style.py", line 201, in format_styled_text
    formatted_parts.append(escape_seq + raw_text)
                           ~~~~~~~~~~~^~~~~~~~~~
TypeError: can only concatenate str (not "NoneType") to str

@ronttizz
Copy link
Author

ronttizz commented Jul 3, 2024

cli.azure.cli.core.sdk.policies: Request URL: 'https://management.azure.com/subscriptions?api-version=2022-12-01'
...
cli.azure.cli.core.sdk.policies: Response content:
// Not sure if I can post the contents of the array so I deleted it for safety
cli.azure.cli.core.sdk.policies: {"value":[]}
cli.azure.cli.core.azclierror: Traceback (most recent call last):
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 664, in execute
    raise ex
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 731, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 701, in _run_job
    result = cmd_copy(params)
             ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 334, in __call__
    return self.handler(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
    return op(**command_args)
           ^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/command_modules/profile/custom.py", line 175, in login
    selected = SubscriptionSelector(subscriptions)()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/command_modules/profile/_subscription_selector.py", line 19, in __init__
    self._format_subscription_table()
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/command_modules/profile/_subscription_selector.py", line 52, in _format_subscription_table
    'Tenant': highlight_text(self._get_tenant_string(sub), is_default)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/command_modules/profile/_subscription_selector.py", line 31, in highlight_text
    return format_styled_text((Style.HIGHLIGHT, text)) if row_is_default else text
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.61.0/libexec/lib/python3.11/site-packages/azure/cli/core/style.py", line 201, in format_styled_text
    formatted_parts.append(escape_seq + raw_text)
                           ~~~~~~~~~~~^~~~~~~~~~
TypeError: can only concatenate str (not "NoneType") to str

@ronttizz
Copy link
Author

ronttizz commented Jul 3, 2024

It seems that this error is not blocking me from the login itself like @TheOnlyWei pointed out.

@jiasli
Copy link
Member

jiasli commented Sep 4, 2024

As I expected, the responses of all these https://management.azure.com/tenants?api-version=2022-12-01 REST calls lack displayName. I have created #29245 to handle it, but I will also report it to ARM team.

Before #29245 is merged and released, you may disable the subscription selector by running

az config set core.login_experience_v2=off

See https://learn.microsoft.com/en-us/cli/azure/authenticate-azure-cli-interactively#subscription-selector

@KKamishima
Copy link

Probably the same thing happed to me 😩 It's on a Windows box.

>az login
Select the account you want to log in with. For more information on login with Azure CLI, see https://go.microsoft.com/fwlink/?linkid=2271136

Retrieving tenants and subscriptions for the selection...
The command failed with an unexpected error. Here is the traceback:
can only concatenate str (not "NoneType") to str
Traceback (most recent call last):
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 233, in invoke
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 666, in execute
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 733, in _run_jobs_serially
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 703, in _run_job
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 336, in __call__
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 121, in handler
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/profile/custom.py", line 182, in login
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/profile/_subscription_selector.py", line 19, in __init__
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/profile/_subscription_selector.py", line 52, in _format_subscription_table
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/profile/_subscription_selector.py", line 31, in highlight_text
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/style.py", line 201, in format_styled_text
TypeError: can only concatenate str (not "NoneType") to str
To check existing issues, please visit: https://github.com/Azure/azure-cli/issues

I am using the latest CLI.

>az --version
azure-cli                         2.65.0

In my case, the account used is an External Identity to the directory, and indeed I am not able to retrieve the tenant's Name even on Azure Portal with the account.
Image

Here is the view of the same tenant from the tenant's owner.
Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Account az login/account Auto-Assign Auto assign by bot Auto-Resolve Auto resolve by bot Azure CLI Team The command of the issue is owned by Azure CLI team customer-reported Issues that are reported by GitHub users external to the Azure organization. Possible-Solution question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Similar-Issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants