Python can't use request to upload an attachment to an issue

I am trying to use Python and Request module to upload an attachment (.PNG file, about 72KB) to an Issue by calling this REST API attachments:

    headers = {
        "X-Atlassian-Token": "no-check",
        "Content-Type": "multipart/form-data;boundary=----SILVERPEAKTESTEXECUTIONSSUMMARY"

    files = {"file": open(attachment,"rb")}

    result =, auth=(speakConfig["username"], speakConfig["password"]), headers=headers, files=files)

Here, jurl is

but I always get the response:

    result.status_code: 200
    result.txt: []

and this attachment is not uploaded, how to resolve this issue?

This REST API says:

  The name of the multipart/form-data parameter that contains attachments must be "file"

How should I set this parameter in Python script?

Would anyone like to give me some helps?

Any helps would be appreciated!


The key to getting this to work was in the multipart-encoded files:

import requests

# Parse authentication credentials
credentials  = requests.auth.HTTPBasicAuth('USERNAME','PASSWORD')

# JIRA required header
headers = { 'X-Atlassian-Token': 'no-check' }

# Setup multipart-encoded file
files = [ ('file', (filename, open('/path/to/file.txt','rb'), mime_type)) ]

# Run request
r =, auth=credentials, files=files, headers=headers)

This is basically a copy+paste of my Stack Overflow post.