我正在尝试在 Confluence REST API Python 站点上运行该示例,以向 wiki 页面添加评论。在 parentPage 工作之前的所有内容(例如,它从我们的 Intranet wiki 获取正确的页面),但是当我运行 requests.post 时,它实际上并没有向找到的页面添加评论。取而代之的是 printResponse(r),打印出 wiki 中的所有页面(不是我找到的页面)。
我有以下脚本:
#!/usr/bin/python
import requests, json
base_url = 'http://intranet.company.com/rest/api/content'
username = 'username'
password = 'password'
def printResponse(r):
print '{} {}\n'.format(json.dumps(r.json(), sort_keys=True, indent=4, separators=(',', ': ')), r)
r = requests.get(base_url,
params={'title' : 'Space M Homepage'},
auth=(username, password))
printResponse(r)
parentPage = r.json()['results'][0]
pageData = {'type':'comment', 'container':parentPage,
'body':{'storage':{'value':"<p>New comment!</p>",'representation':'storage'}}}
r = requests.post(base_url,
data=json.dumps(pageData),
auth=(username,password),
headers=({'Content-Type':'application/json'}))
printResponse(r)