如何使用Python SDK访问Azure广告?
我可以通过下面的代码访问Azure资源:如何使用Python SDK访问Azure广告?,python,azure-active-directory,Python,Azure Active Directory,我可以通过下面的代码访问Azure资源: from azure.common.credentials import ServicePrincipalCredentials from azure.mgmt.resource import ResourceManagementClient from azure.mgmt.compute import ComputeManagementClient from azure.graphrbac import GraphRbacManagementClien
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.resource import ResourceManagementClient
from azure.mgmt.compute import ComputeManagementClient
from azure.graphrbac import GraphRbacManagementClient
subscription_id = "aaaa"
tenant_id = "bbbb"
credentials = ServicePrincipalCredentials(
client_id="cccc",
secret="dddd",
tenant=tenant_id
)
client = ResourceManagementClient(credentials, subscription_id)
for item in client.resource_groups.list():
print item
compute_client = ComputeManagementClient(credentials, subscription_id)
disks = compute_client.disks.list()
for disk in disks:
print disk
graphrbac_client = GraphRbacManagementClient(credentials, subscription_id)
for item in graphrbac_client.groups.list():
print item
但是我不能用相同的代码访问Azure广告!!!是否有其他方式访问它?为什么不一样?!请参见下面的代码:
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.resource import ResourceManagementClient
from azure.mgmt.compute import ComputeManagementClient
from azure.graphrbac import GraphRbacManagementClient
subscription_id = "aaaa"
tenant_id = "bbbb"
credentials = ServicePrincipalCredentials(
client_id="cccc",
secret="dddd",
tenant=tenant_id
)
client = ResourceManagementClient(credentials, subscription_id)
for item in client.resource_groups.list():
print item
compute_client = ComputeManagementClient(credentials, subscription_id)
disks = compute_client.disks.list()
for disk in disks:
print disk
graphrbac_client = GraphRbacManagementClient(credentials, subscription_id)
for item in graphrbac_client.groups.list():
print item
错误:
GrapherErrorExceptionTraceBack(最近一次呼叫上次)
在()
1 graphrbac_客户端=graphrbac管理客户端(凭据、订阅id)
2.
---->3对于graphrbac_client.groups.list()中的项:
4打印项目
/home/andre/.local/lib/python2.7/site-packages/msrest/paging.pyc in
下一步(自我)
129返回响应
130其他:
-->131.自我进阶(第页)
132返回自我。下一步()
133
/home/andre/.local/lib/python2.7/site-packages/msrest/paging.pyc in
高级页面(自我)
115提升停止迭代(“分页结束”)
116自我。当前页面索引=0
-->117 self.\u response=self.\u get\u next(self.next\u链接)
118 self.\u反序列化程序(self,self.\u响应)
119返回自身当前页面
/home/andre/.local/lib/python2.7/site-packages/azure/graphrbac/operations/groups\u operations.pyc
在内部分页中(下一个链接,原始)
336
337如果response.status_代码不在[200]中:
-->338提升模型。图示错误异常(自我反序列化,响应)
339
340返回响应
GrapherErrorException:访问令牌丢失或格式错误
azure通用版本=1.1.14
访问令牌丢失或格式不正确
ComputeManagementClient
资源路径为https://management.azure.com
但是对于GraphRbacManagementClient,资源路径是https://graph.windows.net
。所以你得到了例外
如何使用Python SDK访问Azure广告
你可以从这里得到答案。以下代码是文档中的代码段
from azure.graphrbac import GraphRbacManagementClient
from azure.common.credentials import UserPassCredentials
# See above for details on creating different types of AAD credentials
credentials = UserPassCredentials(
'user@domain.com', # Your user
'my_password', # Your password
resource="https://graph.windows.net"
)
tenant_id = "myad.onmicrosoft.com"
graphrbac_client = GraphRbacManagementClient(
credentials,
tenant_id
)
谢谢它正在工作。您知道是否有可能获取有关用户的多因素身份验证(MFA)数据吗?在SDK中的什么地方?
您知道是否可以获取用户的多因素身份验证(MFA)数据吗?
据我所知,MFA不受支持。