我正在尝试通过Python requests模块更新Atlassian confluence页面中已经存在的页面。我使用requests.put()方法发送更新页面的http请求。该页面已具有标题"Update Status“。我正在尝试输入一行作为页面的内容。json有效负载中的页面id和其他信息是我直接从rest/api/content复制的……我正在尝试访问的网页的输出。注意:我已经能够通过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)我猜有效载荷的格式不正确。有什么建议吗?注意:这里显示的链接、用户名和密码都是虚构的。
发布于 2021-04-24 04:03:14
尝试使用"json“命名参数而不是" data”发送数据,这样请求模块就会将application/json设置为content-type头。
result = requests.put(url, json=payload, auth=HTTPBasicAuth('svc-Automation@ai.com', 'AIengineering1@ai'))https://stackoverflow.com/questions/67236157
复制相似问题