You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用atlassian-python-api调用create_page失败,查询及追加页面正常

Confluence API调用create_page报错:无法创建类型为page的内容

问题描述

使用atlassian-python-api连接本地Confluence时,get_page_by_id和append_page功能均可正常运行,且账号拥有该空间及服务器的全部权限,但调用create_page接口(无论是否指定parent_id参数)均报错:Could not create content with type page。

测试代码

from atlassian import Confluence

def test_axway_connection():
    local_confluence = Confluence(url='http://localhost:8090', username='myname', password='mypassword')
    # 正常运行:获取页面信息
    toto = local_confluence.get_page_by_id(2359298)
    print(toto)
    # 正常运行:追加页面内容
    # local_confluence.append_page(2359300, 'AAA2', 'Appended body here')
    # 运行失败
    tata = local_confluence.create_page(space='AAA', title='Created with api', body='this is the body')
    print(f"tata={tata}")
    # 同样运行失败
    tata = local_confluence.create_page(space='AAA', title='Created with api', parent_id=2359298, body='this is the body')
    print(f"tata={tata}")

完整错误输出

venv\conversion_scripts\pytest_test.py:29 (test_axway_connection)
def test_axway_connection():
        local_confluence = Confluence(
            url='http://localhost:8090',
            username='uuuuuu',
            password='ppppppp')
        toto = local_confluence.get_page_by_id(2359298)
        print (toto)
>       tata = local_confluence.create_page(space='AAA', title='Created with api',  body='this is the body' )

pytest_test.py:46: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\lib\site-packages\atlassian\confluence.py:701: in create_page
    response = self.post(url, data=data)
..\lib\site-packages\atlassian\rest_client.py:309: in post
    response = self.request(
..\lib\site-packages\atlassian\rest_client.py:242: in request
    self.raise_for_status(response)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <atlassian.confluence.Confluence object at 0x0000020D6B9841F0>
response = <Response [400]>

    def raise_for_status(self, response):
        """
        Checks the response for an error status and raises an exception with the error message provided by the server
        :param response:
        :return:
        """
        if 400 <= response.status_code < 600:
            try:
                j = response.json()
                error_msg = j["message"]
            except Exception:
                response.raise_for_status()
            else:
>               raise HTTPError(error_msg, response=response)
E               requests.exceptions.HTTPError: Could not create content with type page

..\lib\site-packages\atlassian\confluence.py:2774: HTTPError

解决办法

  • 核实空间键准确性:确认space='AAA'是Confluence空间的实际空间键,而非空间名称。空间键可在空间设置页或空间首页的URL中获取(如URL路径里的key=AAA部分)。
  • 修正body内容格式:Confluence API要求页面内容符合存储格式(XHTML或Wiki标记),纯文本可能无法被识别。尝试将body改为<p>this is the body</p>这类标准格式,或使用API的convert_storage_format方法转换内容格式。
  • 指定内容格式参数:调用create_page时显式添加representation='storage'参数,明确告知API内容格式,示例代码:
    tata = local_confluence.create_page(
        space='AAA', 
        title='Created with api', 
        body='<p>this is the body</p>', 
        representation='storage'
    )
    
  • 检查版本兼容性:确认atlassian-python-api版本与本地Confluence版本匹配,部分旧版本Confluence可能需要显式指定type='page'参数。
  • 查看Confluence日志:在本地Confluence的confluence/logs/目录下查找详细日志,400错误通常会在日志中记录具体原因(如空间不存在、标题规则冲突等)。

内容的提问来源于stack exchange,提问作者Francis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 16:07:08