【发布时间】:2021-07-18 00:40:09
【问题描述】:
我正在尝试通过 Python 请求模块更新 Atlassian Confluence 页面中已经存在的页面。我正在使用 requests.put() 方法发送 http 请求以更新我的页面。该页面已有标题“更新状态”。我正在尝试输入一行作为页面的内容。我直接从我尝试访问的网页的 rest/api/content... 输出中复制了 json 有效负载中的页面 ID 和其他信息。 注意:我已经能够通过 python requests.get 从网页访问信息,但我无法将信息发布到网页。
用于从有效网页访问信息的方法:
response = requests.get('https://confluence.ai.com/rest/api/content/525424594?expand=body.storage',
auth=HTTPBasicAuth('svc-Automation@ai.com', 'AIengineering1@ai')).json()
用于将信息更新到该页面的方法不起作用,因为响应是错误 415 的形式。
import requests
from requests.auth import HTTPBasicAuth
import json
url = "https://confluence.ai.com/rest/api/content/525424594"
payload = {"id":"525424594","type":"page", "title":"new page-Update Status","space":{"key":"TST"},"body":{"storage":{"value": "<p>This is the updated text for the new page</p>","representation":"storage"}}, "version":{"number":2}}
result = requests.put(url, data=payload, auth=HTTPBasicAuth('svc-Automation@ai.com', 'AIengineering1@ai'))
print (result)
我猜测有效负载的格式不正确。有什么建议? 注意:此处显示的链接、用户名和密码均为虚构。
【问题讨论】:
标签: python json python-requests httprequest http-status-code-415