我正在尝试使用python lib azure.mgmt.resourcegraph 来接收我的租户中所有cosmosdb帐户的列表。
这是代码:
from azure.mgmt.subscription import SubscriptionClient
from msrestazure.azure_active_directory import ServicePrincipalCredentials
from azure.mgmt.resourcegraph import ResourceGraphClient
credentials = ServicePrincipalCredentials(client_id, secret, tenant=tenant_id)
rgraph_object = ResourceGraphClient(credentials)
test = rgraph_object.resources(query="resources | where type == 'microsoft.documentdb/databaseaccounts'")
错误:AttributeError:'str'对象没有属性'get'
有人可以帮忙吗?
答案 0 :(得分:1)
此:
inline
应该是这样:
inline bool operator!=(const Sales_item& lhs, const Sales_item& rhs)
答案 1 :(得分:1)
嗯,我找到了原因。 通常,方法资源使用特定类型“ QueryRequest”
因此,正确的代码是:
from azure.mgmt.subscription import SubscriptionClient
from msrestazure.azure_active_directory import ServicePrincipalCredentials
from azure.mgmt.resourcegraph import ResourceGraphClient
from azure.mgmt.resourcegraph.models import QueryRequest
credentials = ServicePrincipalCredentials(client_id, secret, tenant=tenant_id)
sub_object = SubscriptionClient(credentials)
rgraph_object = ResourceGraphClient(credentials)
subs = [sub.as_dict() for sub in sub_object.subscriptions.list()]
subs_list = []
for sub in subs:
subs_list.append(sub.get('subscription_id'))
request = QueryRequest(subscriptions=subs_list, query="resources | where type == 'microsoft.documentdb/databaseaccounts'")
test = rgraph_object.resources(request)