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 组列表?


基础教程推荐
- 求两个直方图的卷积 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 包装空间模型 2022-01-01