Python requests 带有python请求的修补程序页面抛出;请求';s JSON无效";-MS OneNote API
我想用MS Graph更新OneNote页面,但出现以下错误:Python requests 带有python请求的修补程序页面抛出;请求';s JSON无效";-MS OneNote API,python-requests,onenote-api,Python Requests,Onenote Api,我想用MS Graph更新OneNote页面,但出现以下错误: { "error": { "code": "20109", "message": "The request's JSON was invalid or could not be parsed.", "innerError": { "date": "
{
"error": {
"code": "20109",
"message": "The request's JSON was invalid or could not be parsed.",
"innerError": {
"date": "2020-11-17T07:22:13",
"request-id": "a5d97ae9-d792-4e7e-8b98-3ff450916905",
"client-request-id": "a5d97ae9-d792-4e7e-8b98-3ff450916905"
}
}
}
我的代码:
dest = f'https://graph.microsoft.com/v1.0/me/onenote/pages/{page_id}/content'
payload = {
'target': 'body',
'action': 'prepend',
'content': '<p>New paragraph as first child in the first div</p>'
}
print(page_id)
print(json.dumps(payload))
print(app.session.get(app.ACCESS_TOKEN))
headers = {'Authorization': 'Bearer ' + app.session.get(app.ACCESS_TOKEN), 'Content-Type': 'application/json'}
result = requests.patch(dest, json.dumps(payload), headers=headers)
print(result.text)
dest=f'https://graph.microsoft.com/v1.0/me/onenote/pages/{page_id}/content'
有效载荷={
'target':'body',
“操作”:“预结束”,
“内容”:“新段落作为第一个div中的第一个子段落”
}
打印(页码号)
打印(json.dumps(有效负载))
打印(app.session.get(app.ACCESS_令牌))
headers={'Authorization':'Bearer'+app.session.get(app.ACCESS_TOKEN),'Content Type':'application/json'}
结果=requests.patch(dest,json.dumps(有效负载),headers=headers)
打印(result.text)
我已经试过了:
result=requests.patch(dest,data=json.dumps(有效负载),headers=headers)
result=requests.patch(dest,json=json.dumps(有效负载),headers=headers)
result=requests.patch(dest,json=payload,headers=headers)
payload=[
{
'target':'body',
“操作”:“预结束”,
“内容”:“新段落作为第一个div中的第一个子段落”
}
]
然后尝试这样做请求:
result=requests.patch(dest,json=payload,headers=headers)
json=
参数已经为您执行了json.dumps
转换