我按照微软的官方说明为Ubuntu安装了Azure命令行实用程序。
https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-linux?pivots=apt
我能够使用Azure进行身份验证,但现在我在列出资源时遇到问题:
$ az resource list
我的结果是一个错误:
CLIInternalError: The command failed with an unexpected error. Here is the traceback:
API version 2020-10-01 does not have operation group 'resources'
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/knack/cli.py", line 233, in invoke
cmd_result = self.invocation.execute(args)
File "/usr/lib/python3/dist-packages/azure/cli/core/commands/__init__.py", line 659, in execute
raise ex
File "/usr/lib/python3/dist-packages/azure/cli/core/commands/__init__.py", line 722, in _run_jobs_serially
results.append(self._run_job(expanded_arg, cmd_copy))
File "/usr/lib/python3/dist-packages/azure/cli/core/commands/__init__.py", line 715, in _run_job
six.reraise(*sys.exc_info())
File "/usr/lib/python3/dist-packages/six.py", line 703, in reraise
raise value
File "/usr/lib/python3/dist-packages/azure/cli/core/commands/__init__.py", line 693, in _run_job
result = cmd_copy(params)
File "/usr/lib/python3/dist-packages/azure/cli/core/commands/__init__.py", line 330, in __call__
return self.handler(*args, **kwargs)
File "/usr/lib/python3/dist-packages/azure/cli/core/__init__.py", line 786, in default_command_handler
return op(**command_args)
File "/usr/lib/python3/dist-packages/azure/cli/command_modules/resource/custom.py", line 2015, in list_resources
resources = rcf.resources.list(filter=odata_filter, expand=expand)
File "/usr/lib/python3/dist-packages/azure/mgmt/resource/resources/_resource_management_client.py", line 396, in resources
raise ValueError("API version {} does not have operation group 'resources'".format(api_version))
ValueError: API version 2020-10-01 does not have operation group 'resources'
To open an issue, please run: 'az feedback'
请尝试将Azure CLI更新到最新版本,然后再试一次。
如果它仍然不起作用,您可以使用az rest
直接调用REST API,它对az resource list
做同样的事情。
az rest --method get --url https://management.azure.com/subscriptions/<subscription-id>/resources?api-version=2021-04-01
我发现解决方案是清除Ubuntu软件包并使用pip通过pypi安装azure:
$ pip install azure-cli
那么az刚刚工作。
https://pypi.org/project/azure-cli/