Python: Adding XML Payload to Requests POST Isn't Working


I am submitting media processing jobs to a media transcode API.

It is REST based and accepts a few values in the call:

  • workflowIdentifier (required): unique ID to the API, this is static
  • sourceFilename (required): url encoded samba UNC path
  • jobName (optional): string
  • context (optional): This is an XML payload read by the API

Here is what an example manual submit would look like (with much of the XML truncated for readability)


When the XML (for context) is small enough THIS WORKS

However in our production environment it's a VERY large XML payload to be sent to "context" so I'm getting:

<hr><p>HTTP Error 414. The request URL is too long.</p>

- So after doing a bit of searching, I've tried the following

context_string = (the very large XML document as a string)
source_file =
job_name = 'testjob'
workflow_id = '4r5t6y7u'
url = '' + workflow_id + '&sourceFilename=' + source_file + '&jobName=' + job_name
reply =, data={'context': context_string})

The job is successfully accepted by the API, BUT the context payload is ignored.

(Please note that I've tried with the XML url encoded, and as a normal string )

I also tried it like this:

context_string = (the very large XML document as a string)
source_file =
job_name = 'testjob'
workflow_id = '4r5t6y7u'
payload = {'workflowIdentifier': workflow_id, 'sourceFilename': source_file, 'context': context_stringa, 'jobName': jobname}
reply =, data=payload)

This doesn't work at all, it fails since the required fields are not found (such as workflowIdentifier

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=)

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.


So I did a packet capture on the POST call: Here is the command I sent:, data={'context': context_string})

Here is what it looks like on the packet capture:

POST /SubmitRest/SubmitFile?workflowIdentifier=4r5t6y7u& 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=<Context xmlns="http://Telestream.Vantage.Sdk/2010/07" xmlns:i=""><xmlns i:nil="true" xmlns="" xmlns:a=""/>
(omitted the rest of the XML)

Show source
| rest   | xml   | python   | api   | python-requests   2016-10-13 09:10 0 Answers

Answers ( 0 )

◀ Go back