confluence-rest-apiatlassian-python-api

atlassian-python-api for Confluence: get_page_by_id works, create_page doen't


The message is Could not create content with type page The connection works with get_page_by_id, and of course I have all privileges on the space and the server. append_page works also. Just create_page does not work. Here's the code I'm trying to run.

from atlassian import Confluence

def test_axway_connection():
    local_confluence = Confluence(   url='http://localhost:8090',   username='myname',  password='mypassword')
    # THIS WORKS:  
    # (here I get a printout starting with {'id': '2359298', 'type': 'page', 'status': 'current', 'title': 'AAA Home', ...)
    toto = local_confluence.get_page_by_id(2359298)
    print (toto)  
    # THIS WORKS TOO:
    # local_confluence.append_page( 2359300, 'AAA2', 'Appended body here')
    # THIS DOES NOT WORK (see error printout below) 
    tata = local_confluence.create_page(space='AAA', title='Created with api',  body='this is the body' )
    print(f"tata={tata}")
    # THIS DOES NOT WORK EITHER (same printout) 
    tata = local_confluence.create_page(space='AAA', title='Created with api', parent_id=2359298, body='this is the body' )
    print(f"tata={tata}")

Here's the complete error printout:

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



Solution

  • I entered the following commands:

    pip uninstall atlassian-python-api
    pip install atlassian-python-api
    

    in my python installation and now it seems to work.