mailgun sent attachments are 1kb blank images
<p>I have a very simple django based server i wish to use as an email sending server with mailgun</p>

<p>I've managed to create a server endpoint that trigger an email with an attachment, this seems to work fine but when checking out the received email the attachment jpg file is just a 1kb blank image, im not sure if its a django issue, mailgun or even the fact that its a sandbox domain</p>

<p>here is my code including imports:</p>

<pre><code>from django.shortcuts import render
from django.http import HttpResponse
from rest_framework import generics
import requests

class Email(generics.GenericAPIView):
    def post(self, req, *args, **kwargs):
        response =  requests.post("https://api.mailgun.net/v3/sandbox....mailgun.org/messages",
                            auth=("api", "&lt;API_KEY&gt;"),
                            files=[("attachment", open("files/test.jpg"))],
                            data={"from": "Dummy user &lt;mg.mymail@gmail.com&gt;",
                                  "to": ["mymail@gmail.com"],
                                  "subject": "Hello worlds",
                                  "text": "testing this thing out"})
        resString = str(response)
        return HttpResponse(resString)
</code></pre>

<p>As an answer instead of in comments - you're reading your files in text mode, not binary mode.  That'll introduce odd line endings or otherwise mangle your files before you submit them to MailGun's API.  You want to read your files in binary mode like so:</p>

<pre><code>open('path/to/file', 'rb')
</code></pre>

python django mailgun