问题描述
祝您有美好的一天。
当我尝试使用 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},data=json.dumps(html))
b'{\r\n "error": {\r\n "code": "BadRequest",\r\n "message":
“实体仅允许使用 JSON Content-Type 标头写入。”,\r\n
"innerError": {\r\n "date": "2021-02-17T06:52:50",\r\n
"request-id": "708cbd3b-5b3c-489a-a69d-29903b40d5e0",\r\n
"client-request-id": "708cbd3b-5b3c-489a-a69d-29903b40d5e0"\r\n
}\r\n }\r\n}'
我也尝试使用 lxml 模块搜索创建 html,但效果不佳。
感谢您的帮助
解决方法
使用不正确的 API 链接是我的错误
应该
URL_PAGE
'https://graph.microsoft.com/v1.0/me/onenote/sections/{id}/pages'
代替
'https://graph.microsoft.com/v1.0/me/sections/{id}/pages'