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

Confluence: Upload attachment not possible

Open Mordecaine opened this issue 4 years ago • 0 comments

Hello,

I try to upload a file to a confluence site with the following code

    confluence = Confluence(
        url="https://confluence.example.com",
        username="username",
        password="password",
    )

    response = confluence_object.attach_file(
            "/tmp/mypdf.pdf,
            content_type="application/pdf",
            name="mypdf",
            page_id="151685342",
            title="mypdf",
            space='SPKD',
            comment="test"
        )

If I use this command, I get the following error:

Traceback (most recent call last):
  File "/home/t1-*******/PycharmProjects/CQ-deploy-reports/venv/lib64/python3.6/site-packages/atlassian/confluence.py", line 1029, in attach_content
    files={"file": (name, content, content_type)},
  File "/home/t1-*******/PycharmProjects/CQ-deploy-reports/venv/lib64/python3.6/site-packages/atlassian/rest_client.py", line 312, in post
    absolute=absolute,
  File "/home/t1-*******/PycharmProjects/CQ-deploy-reports/venv/lib64/python3.6/site-packages/atlassian/rest_client.py", line 236, in request
    response.raise_for_status()
  File "/home/t1-*******/PycharmProjects/CQ-deploy-reports/venv/lib64/python3.6/site-packages/requests/models.py", line 943, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error:  for url: https://***********************/rest/api/content/151685342/child/attachment
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "<input>", line 136, in upload
  File "/home/t1-*******/PycharmProjects/CQ-deploy-reports/venv/lib64/python3.6/site-packages/atlassian/confluence.py", line 1100, in attach_file
    comment=comment,
  File "/home/t1-*******/PycharmProjects/CQ-deploy-reports/venv/lib64/python3.6/site-packages/atlassian/confluence.py", line 1037, in attach_content
    reason=e,
atlassian.errors.ApiError: Attachments are disabled or the calling user does not have permission to add attachments to this content
report.upload_page_id
'151685342'

If I use the API without the module, it works really nice.

Is this a bug or is the bug in my mind?

Cheers, Mordecaine

Mordecaine avatar May 17 '21 09:05 Mordecaine