API call failing

Hello Team,

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


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.



Hello Steven,

Thankyou for the reply.

  1. The actual input file looks like


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


This is reading the above input file .

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.