【问题标题】:How to create PAGE using Onenote MS Graph API with Python如何使用 Onenote MS Graph API 和 Python 创建 PAGE
【发布时间】: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


    【解决方案1】:

    使用不正确的 API 链接是我的错误

    应该是

    URL_PAGE
    'https://graph.microsoft.com/v1.0/me/onenote/sections/{id}/pages'
    

    而不是

    'https://graph.microsoft.com/v1.0/me/sections/{id}/pages'
    

    【讨论】:

      猜你喜欢
      • 2021-09-26
      • 2022-10-07
      • 1970-01-01
      • 2022-12-23
      • 2020-12-13
      • 1970-01-01
      • 2021-11-16
      • 1970-01-01
      • 2020-09-05
      相关资源
      最近更新 更多