英文:
Getting "attemted changes conflicted with already accepted changes" error in Microsoft Graph Planner API
问题
I'm getting the following error message when making a patch request to the Planner API:
"尝试的更改与已接受的更改冲突。请阅读最新状态并解决差异。"
Here are your Python scripts for reference:
Get_task.py:
import requests
access_token = '访问令牌'
url = 'https://graph.microsoft.com/v1.0/planner/tasks/{task_id}'
headers = {
'Authorization': access_token,
}
graph_result = requests.get(url=url, headers=headers)
print(graph_result.text)
Patch_task.py:
import requests
plan_e_tag = '计划ETag'
access_token = '访问令牌'
url = 'https://graph.microsoft.com/v1.0/planner/tasks/{task_id}'
headers = {
'Authorization': access_token,
'If-Match': plan_e_tag
}
data = {
"title": "测试"
}
graph_result_patch = requests.patch(url=url, headers=headers, json=data)
print(graph_result_patch.text)
You mentioned that even when running get_task.py first to read the latest state, you still encounter the error when attempting to make changes. The same issue occurs when using Postman. Your goal is to change the task name.
英文:
As in title I'm getting "The attempted changes conflicted with already accepted changes. Read the latest state and resolve differences." error when i'm trying to make patch request to planner api. It works fine in Postman when i'm doing Get planner taks by id first and then Update plan task but when i'm trying to do it in python i'm getting error mentioned above.
Get task works fine because im getting 200 response
Get_task.py
import requests
access_token = 'access token'
url = 'https://graph.microsoft.com/v1.0/planner/tasks/{task_id}'
headers = {
'Authorization': access_token,
}
graph_result = requests.get(url=url, headers=headers)
print(graph_result.text)
Patch_task.py
import requests
plan_e_tag = 'planEtag'
access_token = 'acces token'
url = 'https://graph.microsoft.com/v1.0/planner/tasks/{task_id}'
headers = {
'Authorization': access_token,
'If-Match' : plan_e_tag
}
data = {
"title": "test"
}
graph_result_patch = requests.patch(url=url, headers=headers, json=data)
print(graph_result_patch.text)
I'm trying to run get_task.py first to read the latest state but i'm still getting and error. Same happens when i'm making get request via postman and then running patch_task.py. I'm excpecting to change the name of the task.
答案1
得分: 1
任务的Etag在GET操作中返回。您需要将该值传递给PATCH操作中的If-Match头部。Etag代表客户端了解的实体版本。如果客户端正在编辑的版本已经被同一客户端或其他客户端进行了具有冲突更改的编辑,那么将返回冲突错误。您可以指定一个值为"return=representation"的"prefer"头部,以获取补丁的响应,其中还将包括实体的最新Etag。
英文:
The Etag of the task is returned in the GET operation. You need to pass that value to the If-Match header in the PATCH operation. Etag represents the version of the entity that the client knows about. If the version the client is editing has already been edited with conflicting changes by the same or other clients, then a conflict error is going to be returned. You can specify a "prefer" header with value "return=representation" to get the response of the patch, which will also include the latest etag of the entity.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论