Updating a Confluence 4.X page via XML-RPC with Python

MichaelM April 16, 2013

If I create a page via this method:

s.confluence2.storePage(token, apage)

...the page is created fine.

If I run the same method again, I get this error:

Traceback (most recent call last):
  File "pageinfo.py", line 51, in <module>
    s.confluence2.storePage(token, apage)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1224, in __call__
    return self.__send(self.__name, args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1575, in __request
    verbose=self.__verbose
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1264, in request
    return self.single_request(host, handler, request_body, verbose)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1297, in single_request
    return self.parse_response(response)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1473, in parse_response
    return u.close()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 793, in close
    raise Fault(**self._stack[0])
xmlrpclib.Fault: <Fault 0: 'java.lang.Exception: org.springframework.transaction.UnexpectedRollbackException: Transaction rolled back because it has been marked as rollback-only'>

If I do this method:

s.confluence2.updatePage(token, apage, {'versionComment': '', 'minorEdit': 1})

I get this error:

Traceback (most recent call last):
  File "pageinfo.py", line 52, in <module>
    s.confluence2.updatePage(token, apage, {'versionComment': '', 'minorEdit': 1})
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1224, in __call__
    return self.__send(self.__name, args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1575, in __request
    verbose=self.__verbose
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1264, in request
    return self.single_request(host, handler, request_body, verbose)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1297, in single_request
    return self.parse_response(response)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1473, in parse_response
    return u.close()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 793, in close
    raise Fault(**self._stack[0])
xmlrpclib.Fault: <Fault 0: "java.lang.Exception: com.atlassian.confluence.rpc.RemoteException: You're not allowed to view that page, or it does not exist.">

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 17, 2013

It's difficult to know what's going wrong without seeing all your code. My first guess is that after you call "storePage" for the first time, the return value of this method is the updated page object. You need to call "updatePage" with that reference, otherwise the page ID of the page object is not set on the "apage" variable.

What I mean is, instead of writing this code:

apage = ##TODO: Set up the page you want to create here.
s.confluence.storePage(token, apage)

## Now update the page
s.confluence.updatePage(token, apage) ## WRONG. This will fail "apage" has no page ID.

Write this code:

apage = ##TODO: Set up the page you want to create here.
apage = s.confluence.storePage(token, apage) ## RIGHT! Update the apage variable with the saved page. Now it has a page ID.

## Now update the page
s.confluence.updatePage(token, apage) ## This will work

If I'm on the wrong track, please share your full code snippet so I can have a better understanding of your code.

0 votes
Deepak Jangid February 24, 2014

apage = ##TODO: Set up the page you want to create here.

what value will be there. Please help

Deleted user October 28, 2014

Something like: apage = {"title":"New Page","content":"new content","space":"Space key"}

0 votes
MichaelM April 17, 2013

I think that was it. I didn't realize page ID was required.

thanks!

TAGS
AUG Leaders

Atlassian Community Events