【发布时间】:2021-05-20 01:28:48
【问题描述】:
祝你有美好的一天。
当我尝试使用 Python 在 Onenote 中创建新页面时,希望您能帮助我解决这个问题。
我的代码是
R_HEADERS_NOTE = {
'Host': 'graph.microsoft.com',
'Authorization':'Bearer ' + ['access_token'],
'Content-type': 'text/html'
}
title = "Some demo page title"
text = "Demo for body"
html = "<html><head><title>" + title + "</title></head>"
html += "<body><p>" + text + "</p></body></html>"
create_page = requests.request('POST',base_url + 'me/sections/{id}/pages', \
headers=R_HEADERS_NOTE, data=html)
即使我尝试使用 json 格式
create_page = requests.request('POST',base_url + 'me/sections/{id}, \
headers=R_HEADERS_NOTE, data=json.dumps(html))
响应仍然是错误代码400
b'{\r\n "错误": {\r\n "代码": "BadRequest",\r\n "消息": “实体只允许使用 JSON Content-Type 标头进行写入。”,\r\n
"innerError": {\r\n "日期": "2021-02-17T06:52:50",\r\n
"请求 ID": "708cbd3b-5b3c-489a-a69d-29903b40d5e0",\r\n
“客户端请求 ID”:“708cbd3b-5b3c-489a-a69d-29903b40d5e0”\r\n
}\r\n }\r\n}'
我也尝试使用 lxml 模块搜索创建 html,但效果不佳。
感谢您的帮助
【问题讨论】:
标签: python onenote-api