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

使用Python更新Confluence页面时出现AttributeError报错求助

Python更新Confluence页面时出现AttributeError问题解决

问题代码

status = confluence.update_page(
parent_id=None,  
page_id={con_pageid},
title={con_title},
body='Updated Page. You can use <strong>HTML tags</strong>!')

报错信息

Traceback (most recent call last):
File "update2.py", line 24, in 
status = confluence.update_page(

File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/atlassian/confluence.py", line 1513, in update_page
if not always_update and body is not None and self.is_page_content_is_already_updated(page_id, body, title):

File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/atlassian/confluence.py", line 1433, in is_page_content_is_already_updated
current_title = confluence_content.get("title", None)

AttributeError: 'str' object has no attribute 'get'

问题分析

报错核心是is_page_content_is_already_updated方法中,获取到的页面内容是字符串而非预期的字典格式,大概率由以下原因导致:

  • page_id参数无效:比如直接使用占位符{con_pageid}而非实际页面ID,导致接口返回错误响应文本
  • Confluence对象权限不足:无法正常读取目标页面内容
  • 目标页面不存在:接口返回HTML格式的错误页而非JSON数据

解决方案

1. 修正参数传递

确保page_id和title传入有效取值,直接使用变量而非占位符语法:

# 假设con_pageid、con_title是存储有效取值的变量
status = confluence.update_page(
    parent_id=None,  
    page_id=con_pageid,
    title=con_title,
    body='Updated Page. You can use <strong>HTML tags</strong>!'
)

2. 强制跳过内容检查

添加always_update=True参数,绕过页面内容比对逻辑,直接执行更新:

status = confluence.update_page(
    parent_id=None,  
    page_id=con_pageid,
    title=con_title,
    body='Updated Page. You can use <strong>HTML tags</strong>!',
    always_update=True
)

3. 验证页面可访问性

先调用get_page_by_id确认页面存在且可正常读取:

# 验证页面获取是否正常
page_info = confluence.get_page_by_id(con_pageid, expand='body.storage')
print(page_info)  # 正常输出应为字典格式

4. 规范内容格式

使用Confluence提供的格式化方法处理内容,确保符合平台存储格式要求:

formatted_body = confluence.format('Updated Page. You can use <strong>HTML tags</strong>!')
status = confluence.update_page(
    parent_id=None,  
    page_id=con_pageid,
    title=con_title,
    body=formatted_body,
    always_update=True
)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 09:42:05