title: Python: Adding XML Payload to Requests POST Isn't Working
body: <p>I am submitting media processing jobs to a media transcode API. </p>
  
  <p>It is REST based and accepts a few values in the call:</p>
  
  <ul>
  <li><strong>workflowIdentifier</strong> (required): unique ID to the API, this is static</li>
  <li><strong>sourceFilename</strong> (required): url encoded samba UNC path</li>
  <li><strong>jobName</strong> (optional): string</li>
  <li><strong>context</strong> (optional): This is an XML payload read by the API</li>
  </ul>
  
  <p>Here is what an example manual submit would look like (with much of the XML truncated for readability) </p>
  
  <pre><code>POST http://1.1.1.1:1234/SubmitRest/SubmitFile?workflowIdentifier=4r5t6y7u&amp;sourceFilename=%5C%5C10.10.1.20%5Cteststore%5Cmedia%5CTEST001E1.mov&amp;jobName=mytestjob&amp;context=%3CContext+xmlns%3D%22http%3A%2F%2FTelestream.Vantage.Sdk%2F2010%2F07%22+xmlns%3Ai%3D%22http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchem...
  </code></pre>
  
  <p><strong>When the XML (for context) is small enough THIS WORKS</strong></p>
  
  <p>However in our production environment it's a VERY large XML payload to be sent to "context" so I'm getting: </p>
  
  <pre><code>&lt;hr&gt;&lt;p&gt;HTTP Error 414. The request URL is too long.&lt;/p&gt;
  </code></pre>
  
  <p>-
  So after doing a bit of searching, I've tried the following</p>
  
  <pre><code>context_string = (the very large XML document as a string)
  source_file =
      '%5C%5C10.10.1.20%5Cteststore%5Cmedia%5CTEST001E1.mov'
  job_name = 'testjob'
  workflow_id = '4r5t6y7u'
  url = 'http://1.1.1.1:1234/SubmitRest/SubmitFile?workflowIdentifier=' + workflow_id + '&amp;sourceFilename=' + source_file + '&amp;jobName=' + job_name
  reply = requests.post(url, data={'context': context_string})
  </code></pre>
  
  <p><strong>The job is successfully accepted by the API, BUT the context payload is ignored.</strong></p>
  
  <p>(Please note that I've tried with the XML url encoded, and as a normal string )</p>
  
  <p>I also tried it like this: </p>
  
  <pre><code>context_string = (the very large XML document as a string)
  source_file =
          '%5C%5C10.10.1.20%5Cteststore%5Cmedia%5CTEST001E1.mov'
  job_name = 'testjob'
  workflow_id = '4r5t6y7u'
  payload = {'workflowIdentifier': workflow_id, 'sourceFilename': source_file, 'context': context_stringa, 'jobName': jobname}
  reply = requests.post(url, data=payload)
  </code></pre>
  
  <p>This doesn't work at all, it fails since the required fields are not found (such as workflowIdentifier</p>
  
  <p>Totally stumped on why it is working when I can fit all the data into the one URI, but it doesn't work when I try and add it to a payload with requests(data=) </p>
  
  <p>So my main question is -- how can I submit this via python requests just like if it was all part of the URI POST call? I must be doing something wrong here. </p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>So I did a <strong>packet capture</strong> on the POST call:
  Here is the command I sent: </p>
  
  <pre><code>requests.post(url, data={'context': context_string})
  </code></pre>
  
  <p>Here is what it looks like on the packet capture:</p>
  
  <pre><code>POST /SubmitRest/SubmitFile?workflowIdentifier=4r5t6y7u&amp;sourceFilename=%5C%5C10.10.1.20%5Cteststore%5Cmedia%5CTEST001E1.mov&amp;jobName=testjob HTTP/1.1
  Host: x.x.x.x:1234
  Connection: keep-alive
  Accept-Encoding: gzip, deflate
  Accept: */*
  User-Agent: python-requests/2.11.1
  Content-Length: 20749
  
  context=&lt;Context xmlns="http://Telestream.Vantage.Sdk/2010/07" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt;&lt;xmlns i:nil="true" xmlns="http://schemas.datacontract.org/2004/07/Telestream.Soa.Vocabulary" xmlns:a="http://schemas.datacontract.org/2004/07/System.Xml.Serialization"/&gt;
  (omitted the rest of the XML)
  </code></pre>