Skip to content

Using attach_content on Confluence Server with an existing attachement results in 415 HTTP error #1677

Description

@FSchumacher

When I use the current version 5.0.4 (which contains #1666) on an on-prem confluence server and try to overwrite an existing attachment using attach_content I get a 415 HTTP error (version 4.x works fine with my code).

The exception is:

Traceback (most recent call last):
...
  File "/home/user/project/.venv/lib/python3.14/site-packages/atlassian/confluence/server/__init__.py", line 1253, in attach_file
    return self.attach_content(
           ~~~~~~~~~~~~~~~~~~~^
        infile,
        ^^^^^^^
    ...<5 lines>...
        comment=comment,
        ^^^^^^^^^^^^^^^^
    )
    ^
  File "/home/user/project/.venv/lib/python3.14/site-packages/atlassian/confluence/server/__init__.py", line 1178, in attach_content
    response = self.put(
        path=update_path,
    ...<2 lines>...
        files={"file": (name, content, content_type)},
    )
  File "/home/user/project/.venv/lib/python3.14/site-packages/atlassian/rest_client.py", line 942, in put
    response = self.request(
        "PUT",
    ...<7 lines>...
        advanced_mode=advanced_mode,
    )
  File "/home/user/project/.venv/lib/python3.14/site-packages/atlassian/confluence/server/__init__.py", line 120, in request
    return super(Server, self).request(
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        method=method,
        ^^^^^^^^^^^^^^
    ...<10 lines>...
        allow_redirects=allow_redirects,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/home/user/project/.venv/lib/python3.14/site-packages/atlassian/rest_client.py", line 575, in request
    self.raise_for_status(response)
    ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/home/user/project/.venv/lib/python3.14/site-packages/atlassian/confluence/base.py", line 270, in raise_for_status
    raise HTTPError("\n".join(dict.fromkeys(messages)), response=response)
requests.exceptions.HTTPError: HTTP 415:

When I change the code of that method like the following diff:

index 6b39d38..6e61e4b 100644
--- a/atlassian/confluence/server/__init__.py
+++ b/atlassian/confluence/server/__init__.py
@@ -1175,15 +1175,24 @@ class Server(ConfluenceServerBase):
                     pass
 
                 if existing_attachment:
-                    # Update existing attachment using PUT on the specific attachment ID
                     attachment_id = existing_attachment["id"]
-                    update_path = f"rest/api/content/{attachment_id}"
-                    response = self.put(
-                        path=update_path,
-                        data=data,
-                        headers=headers,
-                        files={"file": (name, content, content_type)},
-                    )
+                    # Update existing attachment using PUT on the specific attachment ID
+                    if self.api_version == "1.0":
+                        update_path = f"{path}/{attachment_id}/data"
+                        response = self.post(
+                            path=update_path,
+                            data=data,
+                            headers=headers,
+                            files={"file": (name, content, content_type)},
+                        )
+                    else:
+                        update_path = f"rest/api/content/{attachment_id}"
+                        response = self.put(
+                            path=update_path,
+                            data=data,
+                            headers=headers,
+                            files={"file": (name, content, content_type)},
+                        )
                 else:
                     # Create new attachment using POST
                     response = self.post(

I can update the attachement without problems using my code.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions