我正在使用Python 3.6开发利用Microsoft Graph的应用程序。
在请求使用请求数据作为嵌套JSON的Graph API时,我得到了非常奇怪的行为。
这是一个成功的请求:
url = f "https://graph.microsoft.com/v1.0/users/{user_id}"
headers = {
'Authorization': f 'Bearer {office365_access_token}',
'Content-Type': 'application/json'
}
data = {
"city": "Tokyo"
}
req = urllib.request.Request(url, json.dumps(data).encode("utf-8"), headers = headers, method = 'PATCH')
urllib.request.urlopen(req)
下一个片段将失败,并显示HTTP Error 400
错误。documentation声明skills
属性是一个String集合,所以我使用了一个字符串值数组:
url = f "https://graph.microsoft.com/v1.0/users/{user_principal_name}"
headers = {
'Authorization': f 'Bearer {office365_access_token}',
'Content-Type': 'application/json'
}
data = {
"skills": ["swift", "python"]
}
req = urllib.request.Request(url, json.dumps(data).encode("utf-8"), headers = headers, method = 'PATCH')
urllib.request.urlopen(req)
唯一的区别是值是否是字符串。我可以将数据字典转储为JSON字符串,所以我不认为代码是错误的,但是我不知道为什么会发生这个错误。
发布于 2019-03-15 23:34:22
这似乎是一个与微软图形本身有关的错误,特别是与User
operation有关。例如下面的查询:
PATCH https://graph.microsoft.com/v1.0/me
Content-type: application/json
{
"skills": [
"Fortran",
"Cobol"
],
"city": "Helsinki"
}
确实失败了,并返回以下错误:
{
"error": {
"code": "BadRequest",
"message": "The request is currently not supported on the targeted entity set"
}
}
同时更新另一个用户属性,例如与User.skills
具有相同Collection(Edm.String)
类型的User.otherMails属性:
PATCH https://graph.microsoft.com/v1.0/me
Content-type: application/json
{
"otherMails": [
"office365admin@gmail.com",
"office365admin@yahoo.com"
],
"city": "Helsinki"
}
成功完成。
解决方法
当User
resource的skills
属性随着其他属性一起更新时,它似乎失败了。但如果只更新a skills
属性,则会更新该属性
PATCH https://graph.microsoft.com/v1.0/me
Content-type: application/json
{
"skills": [
"Fortran",
"Cobol",
"C"
]
}
未发生错误,操作成功完成。
https://stackoverflow.com/questions/55179016
复制相似问题