Skip to Content
Jul 15 at 08:57 AM

Python: Post to SAP BTP Document extraction fails - missing parameter option


Dear all,

I'm currently trying to code a python and a nodeJS middleware to send documents to SAP BTP Document extraction in order to compare the coding effort. While the nodeJS coding works fine, I have some issues with the python coding:

I wrote a class with a method to send the files to the /document/jobs endpoint:

files = {
            'options': (None, json.dumps(myOptions['options']), "text")
prep_req = Request("POST", url, headers=self.headers, files=files, json=myOptions)
prepped = s.prepare_request(prep_req)
settings = s.merge_environment_settings(prep_req.url, {}, None, None, None)
response = s.send(request=prepped, **settings )

Currently, my multipart/form-data request is built like this, which looks fine for me:

b'--e162e5e03e7e7635406e8f0e39bcd31a\r\nContent-Disposition: form-data; name="options"\r\nContent-Type: application/json\r\n\r\n{"clientId": "default"}\r\n--e162e5e03e7e7635406e8f0e39bcd31a--\r\n'

I also tried this option:

b'--34f7d57147e6d352e51440742ea3ff31\r\nContent-Disposition: form-data; name="options"\r\nContent-Type: application/json\r\n\r\n{"options": {"clientId": "default"}}\r\n--34f7d57147e6d352e51440742ea3ff31--\r\n'

And i tried several different content-Types, like "application/json", "text", "text/plain" and much more.

But all my efforts always produce an Error 400 - Bad request:

b'{"error": {"code": "E95", "message": "Required form-data not provided.", "details": [{"code": "0", "message": "Missing parameter(s): options"}]}}\n'

If somebody has information why this seems to be such a struggle with Python, I would be really glad.

Thanks in advance.

Best regards