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

Question

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)

POST http://1.1.1.1:1234/SubmitRest/SubmitFile?workflowIdentifier=4r5t6y7u&sourceFilename=%5C%5C10.10.1.20%5Cteststore%5Cmedia%5CTEST001E1.mov&jobName=mytestjob&context=%3CContext+xmlns%3D%22http%3A%2F%2FTelestream.Vantage.Sdk%2F2010%2F07%22+xmlns%3Ai%3D%22http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchem...

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 =
    '%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 + '&sourceFilename=' + source_file + '&jobName=' + job_name
reply = requests.post(url, 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 =
        '%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)

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.

EDIT:

So I did a packet capture on the POST call: Here is the command I sent:

requests.post(url, data={'context': context_string})

Here is what it looks like on the packet capture:

POST /SubmitRest/SubmitFile?workflowIdentifier=4r5t6y7u&sourceFilename=%5C%5C10.10.1.20%5Cteststore%5Cmedia%5CTEST001E1.mov&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=<Context xmlns="http://Telestream.Vantage.Sdk/2010/07" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><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"/>
(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