Python API conf.update_page fails with simple HTML

Jonathan Abrahams June 30, 2022

Using PIP module atlassian-python-api

The following fails with error
requests.exceptions.HTTPError: com.atlassian.confluence.api.service.exceptions.BadRequestException: Content body cannot be converted to new editor format

from atlassian import Confluence
conf = Confluence(url=conf_site, username=CONF_USER, password=CONF_TOKEN)
page_id = conf.get_page_id(page_space, page_title)
page = conf.get_page_by_id(page_id, expand="body.storage")
page_content = page["body"]["storage"]["value"]

html_table = "<table>Prod version updated<table />"
conf.update_page(page_id, page_title, html_table)

 Similar code block to passing case also fails:

from atlassian import Confluence
conf = Confluence(url=conf_site, username=CONF_USER, password=CONF_TOKEN)
page_id = conf.get_page_id(page_space, page_title)
page = conf.get_page_by_id(page_id, expand="body.storage")
page_content = page["body"]["storage"]["value"]

html_table = "Prod version updated</table>"
conf.update_page(page_id, page_title, html_table)

However this does not:

from atlassian import Confluence
conf = Confluence(url=conf_site, username=CONF_USER, password=CONF_TOKEN)
page_id = conf.get_page_id(page_space, page_title)
page = conf.get_page_by_id(page_id, expand="body.storage")
page_content = page["body"]["storage"]["value"]

html_table = "Prod version updated<table />"
conf.update_page(page_id, page_title, html_table)

 

The code is valid HTML. What is wrong here? 

2 answers

0 votes
Yakov Shkolnikov
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 20, 2023

I have the same issue by using pip module.

0 votes
Jonathan Abrahams June 30, 2022

I get the same error when directly using requests.put:

{"statusCode":400,"data":{"authorized":false,"valid":true,"errors":[],"successful":false},"message":"com.atlassian.confluence.api.service.exceptions.BadRequestException: Content body cannot be converted to new editor format"}

 

version += 1
html_table = "Prod version updated<table></table>"
data = {
"type": page_type,
"title": page_title,
"version": {"number": version},
"body": {"storage": {"value": html_table, "representation": "storage"}},
}

response = requests.put(
f"{content_url}/{page_id}",
headers=HEADERS,
auth=(CONF_USER, CONF_TOKEN),
json=data,
)
print(response.content)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events