How to access the list of Azure AD Groups using python?(如何使用 python 访问 Azure AD 组列表?)
问题描述
我是 Python 新手.我找到了以下示例代码来从 https://msdn.microsoft.com/en-us/Library/Azure/Ad/Graph/api/groups-operations#BasicoperationsongroupsGetgroups
I'm new to python. I found the following sample code to retrieve the Azure AD groups from https://msdn.microsoft.com/en-us/Library/Azure/Ad/Graph/api/groups-operations#BasicoperationsongroupsGetgroups
代码是:
########### Python 3.2 #############
import http.client, urllib.request, urllib.parse, urllib.error, base64
# OAuth2 is required to access this API. For more information visit: https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
headers = {}
params = urllib.parse.urlencode({
# Specify values for the following required parameters
'api-version': '1.5',
})
try:
conn = http.client.HTTPSConnection('graph.windows.net')
#Specify values for path parameters (shown as {...}) and request body if needed
conn.request("GET", "/myorganization/groups?%s" % params, "", headers)
response = conn.getresponse()
data = response.read()
print(data)
conn.close()
except Exception as e:
print("[Errno {0}] {1}".format(e.errno, e.strerror))
####################################
一切都很好,但我不知道headers = {}"的价值是什么.
everything is fine but i don't know what would be the value of "headers = {}".
我需要帮助,为此我花了很多时间,但还没有成功.
I need help i spent a lot of hours on this but no luck yet.
推荐答案
根据我的理解,需要将Oauth Authorization信息写入headers中,如下代码:
Base on my understanding, you need to write the Oauth Authorization information into headers, like the code below:
headers = {
#set your access token
'Authorization':'your access token'
}
在访问 Graph API 之前,您需要从 AD 中获取访问令牌.您可以将授权信息添加到您的标头和请求中.关于如何获取access token,建议大家可以参考这个页面:Active Directory -身份验证方案
Before you accessing the Graph API, you need to get the access token form AD. You can add the authorization information into your headers and request. About how to get the access token, I suggest that you can refer to this page: Active Directory -Authentication Scenarios
这篇关于如何使用 python 访问 Azure AD 组列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 python 访问 Azure AD 组列表?
基础教程推荐
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
