将 HTML 页面加载到汇合时出错:类型为"TextIOWrapper"的对象不可 JSON 序列化



我有一个HTML页面。我想在合流中创建页面并上传该页面中的内容。我能够创建一个页面,如果静态内容是通过变量"f"。但是当将HTML页面作为"f"。我得到以下错误:TypeError:类型'TextIOWrapper'的对象不是JSON可序列化的

看起来像HTML需要转换成不同的格式。我不确定如何解决这个问题。

**——html文件内容

<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>**
---code
import yaml
from atlassian import Confluence
import urllib, mimetypes
import  requests
import codecs,json
confluence = Confluence(
url='https://confluence.com',
username='12344',  # of system where this page would open
password='abcd')
####reading HTML file
f=codecs.open("sample.html", 'r')
print (f.read())

# Create page from scratch
status = confluence.create_page('ABCD' ,#space,
'Report',#title
f ,#'This is the body',#body,
parent_id=123456,### this is the pageid of the page under which new page will be created
type='page',
representation='storage',
editor='v2')
print(status)

f是一个文件描述符。相反,将内容读入一个变量并使用:

with open("sample.html") as f:
content = f.read()
print(content)
status = confluence.create_page('ABCD',
'Report',
content,
parent_id=123456,
type='page',
representation='storage',
editor='v2')