我有一个函数,它试图将网页写入conflune。它将文件名写入页面,而不是发布文件的内容
我正在使用python请求模块写入web页面
我在网页上看到:
../output_files/aws_instance_list/html/aws-master-list-06-05-2019.html
作为页面的唯一内容
这是我用来写入页面的代码:
htmlfile = '../output_files/aws_instance_list/html/aws-master-list-06-05-2019.html'
pageid = 138317098
auth = ('username','password')
write_data(auth, htmlfile, pageid, 'AWS EC2 Instance List')
def write_data(auth, htmlfile, pageid, title = None):
info = get_page_info(auth, pageid)
ver = int(info['version']['number']) + 1
ancestors = get_page_ancestors(auth, pageid)
anc = ancestors[-1]
del anc['_links']
del anc['_expandable']
del anc['extensions']
if title is not None:
info['title'] = title
data = {
'id' : str(pageid),
'type' : 'page',
'title' : info['title'],
'version' : {'number' : ver},
'ancestors' : [anc],
'body' : {
'storage' :
{
'representation' : 'storage',
'value' : str(htmlfile),
}
}
}
data = json.dumps(data)
url = '{base}/{pageid}'.format(base = BASE_URL, pageid = pageid)
r = requests.put(
url,
data = data,
auth = auth,
headers = { 'Content-Type' : 'application/json' }
)
r.raise_for_status()
print("Wrote '%s' version %d" % (info['title'], ver))
print("URL: %s%d" % (VIEW_URL, pageid))
我已经查看了“htmlfile”的内容,可以看到它包含有效的HTML
如何将文件的内容而不是文件名写入页面
你需要读取文件的内容
相关问题 更多 >
编程相关推荐