![](/img/trans.png)
[英]Azure Storage Python sdk - get_container_access_policy Not Working
[英]Azure python sdk not working
#!/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,并执行了所有必要步骤。 但是此示例代码仍然给出以下错误。
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)
我们使用它来创建此示例。
在您提到的示例中,请查看“ requirements.txt ”文件以获取必要的版本。
我的猜测是您正在使用“ pip install azure”,不幸的是,该教程当前无法安装太旧的软件包。 请参阅ReadTheDocs或Github主页上的安装说明:
TL; DR ;,请使用“ pip install --pre azure”或直接使用“ pip install azure-mgmt-compute”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.