I am trying to upload an attachment to Confluence using REST API from python. I get 415 error: unsupported media type.
I understand the content-type is not correct, but I tried some content types and got the same error:
import requests
print("start....................")
url = 'https://confluence.XXX.com/confluence/rest/api/content/' + str(108458915) + '/child/attachment/'
TOKEN = 'XXXXXXXX'
headers = {'X-Atlassian-Token': 'no-check',
"Authorization": f"Bearer {TOKEN}"
} #no content-type here!
file = 'my_file.jpeg'
content_type = 'multipart/form-data'
files = {'file': (file, open(file, 'rb'), content_type)}
print("request....................")
r = requests.post(url, headers=headers, files=files, verify='confluence.XXX.crt')
r.raise_for_status()
I tried the following content-types: 'image/jpeg'
'application/json'
'application/xml'
'application/octet-stream'
'multipart/form-data'
but get the same 415 error:
requests.exceptions.HTTPError: 415 Client Error: for url: https://confluence.XXX.com/rest/api/content/108458915/child/attachment/
I didn't find what is the problem with my first code, but the following code fixed the issue: