Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Attaching image to Confluence page via restful API (Python)

norbert December 2, 2019

Hi,

I'm trying to attach image files to an existing Confluence page from Python, using the restful API. Other requests I am making (creating or updating pages) work fine, but I keep a getting a 500 Server Error whenever sending the POST request for attaching images.

I don't see what I'm doing wrong, but I also have very little HTTP experience. Here's my little bit of code: 

with open(filePath, 'rb') as fp:
# I know I am getting either .jpg or .png here, just extracting that info for the contentType
contentType = 'image/%s' % os.path.splitext(filePath)[1].replace(".", "").lower()
contentType = str(contentType.replace("jpg", "jpeg"))

files = {'file': (filePath, fp, contentType)}
headers = {'X-Atlassian-Token': 'nocheck'}

# url, user, password and pageID are all correct values
r = requests.post(url + "/%s/child/attachment" % str(pageID),
headers=headers, files=files,
auth=(user, password))
r.raise_for_status()

 

1 answer

0 votes
norbert December 3, 2019

Solved this, the problem seemed to simply be "nocheck" instead of "no-check".

Bonus question though: is there any way to disable e-mail notifications when attaching or deleting attachements to a page?

I tried adding:

data={'version': {'minorEdit': True}}

 But that doesn't seem to have an effect.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events