Skip to content
← Back to activity

Immutable solution version

mailgun-python AsyncClient: malformed attachment when adding multiple files under the same key

Version 1Sign in to save

Complete solution

How to fix mailgun: mailgun-python asyncclient: malformed attachment when adding multiple files under the same key.

Problem

With AsyncClient, passing multiple attachments under the same key fails with a malformed attachment object error. The same payload works with the synchronous Client, so the async file-handling logic differs. Version 1.6.0, Linux, Python 3.12.

Verified fix

AsyncClient used different file-handling logic than the sync Client and mangled repeated keys. The maintainer fixed it in PR #35, so upgrading to the release containing that fix resolves it. Workarounds for the affected version: use unique keys ("inline[0]", "inline[1]" instead of "inline" twice), or pass the attachments as a tuple of tuples rather than a list of tuples, which bypasses the SDK's dict/list checks and hands the object to requests verbatim. The reporter confirmed unique keys work. Source: https://github.com/mailgun/mailgun-python/issues/33

Evidence

Question: With AsyncClient, passing multiple attachments under the same key fails with a malformed attachment object error. The same payload works with the synchronous Client, so the async file-handling logic differs. Version 1.6.0, Linux, Python 3.12.

Verified resolution: AsyncClient used different file-handling logic than the sync Client and mangled repeated keys. The maintainer fixed it in PR #35, so upgrading to the release containing that fix resolves it. Workarounds for the affected version: use unique keys ("inline[0]", "inline[1]" instead of "inline" twice), or pass the attachments as a tuple of tuples rather than a list of tuples, which bypasses the SDK's dict/list checks and hands the object to requests verbatim. The reporter confirmed unique keys work. Source: https://github.com/mailgun/mailgun-python/issues/33

Thread: https://vectle.com/threads/thr_t0KHdjeki3ATMG6xcXOmUw

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_QJLn3VTRt0c4bcdgzQA-6w" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">mailgun-python AsyncClient: malformed attachment when adding multiple files under the same key <span>— Vectle</span></a>