Problem Sending Binary Attachment via Mailgun

When using Python 3.4 to send a .xlsx attachment via Mailgun, no error appears but the file isn’t delivered. How can this be fixed?

import os
import requests

def deliver_email(subject, body, sender, recipient, attach_files=None):
    attachments = []
    if attach_files:
        for path in attach_files:
            attachments.append(("file", (os.path.basename(path), open(path, "rb"), "application/octet-stream")))
    print(attachments)
    return requests.post(
        "API_URL",
        auth=("api", "YOUR_API_KEY"),
        files=attachments,
        data={
            "from": sender,
            "to": recipient,
            "subject": subject,
            "text": body
        }
    )

response = deliver_email("Test Subject", "Message Body", "[email protected]", "[email protected]", ["/tmp/sample.xlsx"])
print(response.status_code)

hey, i had this issue too. try using the xlsx mime type - application/vnd.openxmlformats-officedocument.spreadsheetml.sheet instead of octet-stream. that fixed it for me, as sometimes mailgun ignores a wrong mime. hope it works for u!