title: Trello API - 400: "Error parsing body" when POSTing a multipart file attachment
body: <p>I'm trying to upload a PDF as an attachment to a Trello card using <code>python-requests</code>. I've been unable to get the request in the function below to return anything other than <code>400: Error parsing body</code> despite significant tweaks (detailed below). </p>
  
  <p>I should note that I'm able to create cards and add URL attachments to them (neither of which require a file upload) without any problems.</p>
  
  <p>Here's the code that handles the POST of the file:</p>
  
  <pre><code>def post_pdf(session, design, card_id):
      attachment = {
              "name": design["campaign_title"] + " - Combined PDF",
              "mimeType": "application/pdf"
          }
      pdf_post = session.post(
          url = "https://api.trello.com/1/cards/" + card_id + "/attachments",
          files = {"file": open("combined_pdf.pdf", "rb")}, 
          data = attachment
      ) 
  </code></pre>
  
  <p>The authentication key and token are set Session params when the session was created, so they're not added here.</p>
  
  <p>Also, in the actual code, the <code>POST</code> is handled by a wrapper function that adds some boilerplate error-checking and rate limiting to the request, as well as more-verbose error dumps when a request fails, but I've confirmed (in the above example) that the same error persists without the wrapper.</p>
  
  <hr>
  
  <p><strong>Adjustments I've tried</strong></p>
  
  <ul>
  <li>Substituting <code>data = attachment</code> with <code>json = attachment</code></li>
  <li>Substituting <code>data = attachment</code> with <code>params = attachment</code></li>
  <li>Omitting <code>attachment</code> completely and <code>POST</code>ing the file with no associated data</li>
  <li>Adding <code>stream = True</code> to the request parameters (this doesn't seem to matter for <em>uploads</em>, but I figured it couldn't hurt to try)</li>
  <li>Encoding the file as <code>base64</code> (this encoding has been required elsewhere; I was grasping at straws)</li>
  <li>Encoding the file as <code>base64</code>, combined with the above tweaks to <code>data</code> / <code>json</code> / <code>params</code></li>
  </ul>
  
  <hr>
  
  <p><strong>Note:</strong> The PDF file is potentially a source of the problem - it's generated by converting several images to PDF format and then concatenating them with <code>pdfunite</code>, so I could well have made mistakes in its creation that are causing Trello to reject the file. What seems to confirm this is that Googling for <code>Trello "Error parsing body"</code> returns two hits, only one of which deals with Trello, and neither of which are useful. This leads me to think that this is a particularly odd / rare error message, which means to me that I've made some kind of serious error encoding the file. </p>
  
  <p>However, the PDF file opens properly on my (and my coworkers') systems without any error messages, artifacts, or other strange behavior. More importantly, trying this with other "known good" PDFs also fails, with the same error code. Because the file's contents fall within the bounds of "company property / information", I'd like to avoid posting it (and / or the raw request body), but I'll do so if there's agreement that it's causing the problem. </p>