如何创建新页面并将文本文件上传到汇合空间

时间:2017-08-16 05:35:24

标签: confluence

我有一个脚本获取文本文件作为输出,我希望这个文本文件上传到汇合空间但我不知道如何做到这一点。 这是我在互联网上找到的示例脚本,但这对我不起作用

    import urllib2
import base64
conf_serverurl = "https://confluence.mycompany.com/"
username = "myusername"
password = "mypassword"
stringToEncode = username + ":" + password
encodedString = base64.b64encode(stringToEncode)
url = conf_serverurl + "/rest/api/content?os_username=" + username + "&os_password=" + password
data = '{"type":"page","ancestors":[{"type":"page","id":18166401}],"title":"new page","space":{"key":"ds"},"body":{"storage":{"value":"<p>This is a new page</p>","representation":"storage"}}}'
headers = { 'Authentication': 'Basic ' + encodedString, 'Content-type': 'application/json', 'Accept': 'application/json', 'X-Atlassian-Token': 'no-check' }
req = urllib2.Request(url, data, headers=headers)
try:
    response = urllib2.urlopen(req)
    data = response.read()
except urllib2.HTTPError, error:
    data = error.read()
print data

但是这段代码给我的错误

{"message":"null for uri: https://confluence.mycompany.com//rest/api/content?os_username=ppanda&os_password=mypassword","status-code":404}

这里有什么不妥? 凭证?? /代码??

1 个答案:

答案 0 :(得分:0)

首先我想到你的网址中有"/"conf_serverurl。因为在"https://confluence.mycompany.com/"中你确实有/rest/api/..,并且在你的网址中你会添加/。所以,我想从你的代码中删除import numpy dataset = pd.readCSV('CSV_NAME') dataset = array(dataset) 之一并检查。

另外,请查看Atlassian Documentation以查找创建页面和上传附件的正确REST端点。