API call failing

Hello Team,

I was trying to call API from python code(in EC2) with an below input JSON :

"content-type":"application/octet-stream",
"filename":"sample.json.gz",
"x-odm-authorization-id":"08aca89df364647",
"x-odm-authorization-token":"eyJhbGcXVCJ9.eyJfaWQiOiIwOGFjYTg2YmY2MmI5OTgzNDI1ODQyMTJ9.ChtJ4FGU-sMgRkFGcq4GVJ76-w",
"x-odm-business-unit":"Rack",
"x-odm-country-code":"1",
"x-odm-u_id":"1c4348745468d",
"x-odm-m_id":"101543",
"x-odm-p_id":"30906175",
"Accept":"text/plain"
}

and below is the python code :

    filedata = file_object['Body'].read()
                        d = base64.b64encode(filedata)
                        response = requests.post(cfg.eventlog_endpoint['endpoint'], data=json.dumps(d.decode("utf-8")))
                        print (response.status_code)

but always its resulting in the response code as 417 instead of 200 .

Note, when i try to hit the same input as binary file from insomnia , it results in 200

Any help , please.

Hi Sridhar,

What “API” are you calling?

Literally every single function, class, module, library and framework
has an API. There are a million APIs.

So you need to be more specific: what input is the function expecting,
what input are you providing? Is there a difference between what you
should be providing and what you actually do provide?

Your input JSON seems to be incomplete: there is no opening brace, so I
wonder if there is more missing.

Your sample code is mysterious to me:

  • what does file_object['Body'].read() return?

  • what does cfg.eventlog_endpoint['endpoint'] return?

HTTP status code 417 says the server cannot provide one of the features
your request is asking for:

Can you view the request that requests is actually sending to the
website? I know nothing about requests but perhaps you can see a
difference between the request made with a binary file and a text file,
and see if it is requesting too much.

You mention “insomnia”, but I don’t know what that is. Is it this?

If this is an insomnia problem, you may need to ask for help on an
insomnia forum.

Regards,

Steve

Hello Steven,

Thankyou for the reply.

  1. The actual input file looks like

Blockquote
{
“content-type”:“application/octet-stream”,
“filename”:“1c434878fd60e8d_2018102501143100000219.json.gz”,
“x-odm-authorization-id”:“08acdfdate2b9983”,
“x-odm-authorization-token”:“eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWWF0IjoxNTg2ODI0MjEyLCJleHAiOjQ3NDI1ODQyMTJ9.ChtJ4GibTnGzP3aSOaR2dgFGU-sMgRkFGcq4GVJ76-w”,
“x-odm-business-unit”:“OMP”,
“x-odm-country-code”:“1”,
“x-odm-h_id”:“1c434878fd60e8d”,
“x-odm-m_id”:“101543”,
“x-odm-p_id”:“30906175”
}

this sample file is placed in S3 path (AWS) and im reading the file as input to the code .

Blockquote
file_object[‘Body’].read()

This is reading the above input file .

Blockquote
cfg.eventlog_endpoint[‘endpoint’] → THis is the endpoint that i will be hitting , where in the above JSON is the input.

Insomnia is a tool for sending POST/GET request , in this case , i select the “BINARY FILE” option and provide the above details in the header and check if the response is 200 or anything else.
There isnt any issue with the insomnia , its used for unit/system testing the endpoint and checking its response.

in the logs for the response , i observed that , while sending the request from “insomnia”, the “isBase64Encoded” is set as True . But, while sending the same through the python code i get the response as 417 and in logs observed that “isBase64Encoded” is set as False

sorry in case i havent provided detailed information in earlier post.

let me know if any further questions.