根据官方文档,要列出应用程序注册,必须使用“ApplicationsRequestBuilder”,但没有关于如何导入它的信息。
我的进口是:
import pyodbc
import adal
import struct
import json
import subprocess
import asyncio
from azure.identity import ClientSecretCredential, DefaultAzureCredential
from azure.keyvault.secrets import SecretClient
from msgraph import GraphServiceClient
from msgraph.generated.models.password_credential import PasswordCredential
from msgraph.generated.applications.item.add_password.add_password_post_request_body import AddPasswordPostRequestBody
字符串
我尝试了所有方法,但无法导入。错误是:
File "/azp/_work/1/s/Update_Expired_Service_Principals/sp_renewal.py", line 83, in get_sp_id
query_params = ApplicationsRequestBuilder.ApplicationsRequestBuilderGetQueryParameters(
NameError: name 'ApplicationsRequestBuilder' is not defined
型
我的代码是:
scopes = ['https://graph.microsoft.com/.default']
conn, credential, credentials = get_token()
graph_client = GraphServiceClient(credential, scopes=scopes)
async def get_sp_id():
query_params = ApplicationsRequestBuilder.ApplicationsRequestBuilderGetQueryParameters(
filter = "displayName eq 'test'",
count = True,
top = 1,
)
request_configuration = ApplicationsRequestBuilder.ApplicationsRequestBuilderGetRequestConfiguration(
query_parameters = query_params,
)
request_configuration.headers.add("ConsistencyLevel", "eventual")
app_list = await graph_client.applications.get(request_configuration = request_configuration)
if app_list:
app = app_list[0]
sp_id = await graph_client.applications.by_application_id(app.id).get()
print(sp_id)
return sp_id
return None
型
2条答案
按热度按时间xjreopfe1#
在我的情况下,我有下面的应用程序注册与显示名称为 *'测试'**:
的数据
要获取这些应用注册的objectID,您可以使用以下示例Python代码:
字符串
回复:
的
7uzetpgm2#
为了避免这种错误,需要添加:
字符串