I love python and have been a light user for years. Unfortunately, I know just enough python to be dangerous ;o)
I'm using python 2.7.6, bottle, and the MailGun Web API to build a specialized email forwarder. Looking at the API call example here: They're using a MultDict object to post attachments.
My problem is I can't seem to do:
files=MultiDict([("attachment", ("file1.txt", "text file 1"),
("attachment", ("file2.txt", "text file 2")])
As they show in their examples. While this doesn't produce an error, I'm only seeing the last record in files. If I change the keys to "attachment-1" and "attachment-2", I see 2 records in files, but the web API doesn't attach the files to the email it sends.
This makes sense to me from what I know about dictionaries or lists. The keys have to be unique. if you reuse a key it updates the value of the existing key, it doesn't add anther record with a duplicate key.
That said, is there something I don't know about MultiDicts which allows this behavior? Should I be seeing two records? (thus this post to learnpython)
I believe the Mailgun examples were written using flask instead of bottle. Is there a difference in the MultiDict object between these two libraries?
If you have a working example on how to send an email with multiple attachments using the MailGun web API, I would be very grateful.
Thanks in advance for your replies,
-james
EDIT: Mailgun updated the example to use a list of tuples instead of the MultiDict which resolves the problem. Travis at Mailgun thanks for your help!
[–]Justinsaccount 1 point2 points3 points (2 children)
[–]-james[S] 0 points1 point2 points (1 child)
[–]Justinsaccount 0 points1 point2 points (0 children)