file parameter for Jira attachment

I'm trying to post attachment to Jira Sofware Cloud using

Jira documentation :

I'm using the following code :

def addAttachment(domain, filepath, issue, user, passwd):
baseurl	= "https://" + domain + "/" + str(issue) + "/attachments"

headers = {
   "Accept": "application/json",
   "X-Atlassian-Token": "no-check",

payload = filepath

client    =
response =, username=user, password=passwd, file=payload, headers=headers)

if response.good:
	return str(response) + " | " + response.text
else :
	return str(response) + " | " + response.text

resulting in the following error :' [400]> | {"message":"org.apache.commons.fileupload.FileUploadBase$InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is application/octet-stream","status-code":500,"stack-trace":""}

It seems like the file parameter is not fully compliant with what Jira is waiting for.

Could you help me solving this issue ?

Thank you in advance


Tip: use the </> code formatting button to preserve code indentation and apply syntax highlighting. It's essential for Python and makes any code much easier to read. There's an edit button 🖉 below your post so you can fix it.

1 Like

httpClient doesn't currently have any builtin support for form data requests, unfortunately.

You'll have to manually create the data in the appropriate 'shape' - basically, write out the required header and then append the encoded attachment data, and set the Content-Type header manually.