atlassian-python-api icon indicating copy to clipboard operation
atlassian-python-api copied to clipboard

Problems while using attach_file method in confluence

Open jbtescudeiro16 opened this issue 1 year ago • 3 comments

Recently, I had to create some pages on confluence using a python script. Two pages contain Images. The first time that I attach the image to the page, there's no problem, but when I try and create again the pages and attach files with the same name, it gives me an error. I was expecting that uploading an image with an existing name, a new revision of the image would be created, but that doesn't seems the case. The version i'm using is : atlassian-python-api v1.41.14

The error is : Error while conecting to Confluence org.springframework.transaction.UnexpectedRollbackException: Transaction rolled back because it has been marked as rollback-only

The code i'm using is :

for filename in os.listdir("OutputMD/"):
       file_path = os.path.join("OutputMD/", filename)
       MD_content = read_file_content(file_path)
       page_title = os.path.splitext(filename)[0]
       newpagestats= confluence.update_or_create(page_id, page_title, MD_content, representation='wiki',editor='v2', full_width=True)
       print(newpagestats["id"])
       if page_title in aux_dict:
           for i in aux_dict[page_title]:
               print("Attach files trying")
               confluence.attach_file("Photos/" + i, name=i, content_type=None, page_id=newpagestats["id"], title=page_title,space=None, comment=None)
       print("Page "+ page_title + " created!")
   print("Pages Created!")

jbtescudeiro16 avatar Aug 20 '24 15:08 jbtescudeiro16

+1 I'm having the same issue when trying to update images in Confluence Cloud

j-svensmark avatar Jan 26 '25 12:01 j-svensmark

Using curl as described in the API docs works for me though https://developer.atlassian.com/cloud/confluence/rest/v1/api-group-content---attachments/#api-wiki-rest-api-content-id-child-attachment-attachmentid-put

Just a guess, but maybe the way the python requests lib handles files arguments doesn't rub the confluence server the right way.

j-svensmark avatar Jan 26 '25 14:01 j-svensmark

As I see we need to implement that method

gonchik avatar Mar 17 '25 18:03 gonchik