Azure python sdk不工作
问题描述:
#!/usr/bin/env python
import os
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.compute import ComputeManagementClient
def run_example():
"""Resource Group management example."""
#
# Create all clients with an Application (service principal) token provider
#
subscription_id = os.environ['AZURE_SUBSCRIPTION_ID']
credentials = ServicePrincipalCredentials(
client_id=os.environ['AZURE_CLIENT_ID'],
secret=os.environ['AZURE_CLIENT_SECRET'],
tenant=os.environ['AZURE_TENANT_ID']
)
compute_client=ComputeManagementClient(credentials,subscription_id)
###########
# Prepare #
###########
# List VM in resource group
print('\nList VMs in resource group')
for vm in compute_client.virtual_machines.list():
print("\tVM: {}".format(vm.name))
if __name__ == "__main__":
run_example()
我们在ubuntu服务器上安装了azure python sdk并完成了所有必要的步骤。但这个示例代码仍然存在以下错误。Azure python sdk不工作
Traceback (most recent call last):
File "app.py", line 30, in <module>
run_example()
File "app.py", line 18, in run_example
compute_client=ComputeManagementClient(credentials,subscription_id)
TypeError: __init__() takes exactly 2 arguments (3 given)
我们用this来创建这个例子。
答
在您提到的示例中,请查看“requirements.txt”文件以获取必要的版本。
我的猜测是你使用的是“pip install azure”,不幸的是它会为本教程安装一个过时的包。查看ReadTheDocs或Github上头版安装注意事项:
- http://azure-sdk-for-python.readthedocs.io/en/latest/installation.html
- https://github.com/Azure/azure-sdk-for-python#installation
TL; DR;,请使用 “PIP安装 - 事先蔚蓝” 或直接“PIP安装Azure的MGMT - 计算“
+0
谢谢你:) ..工作很好,我更新了下面的requirements.txt中的python模块as azure-mgmt-compute == 0.30.0rc5&haikunator。 – sas
什么是你的包和python版本? – 4c74356b41
尝试'pip install azure-mgmt-compute == 0.30.0rc5'。 –
@ PeterPan-MSFT:谢谢,现在工作。 – sas