Saturday, 12 October 2019

Read timed out. error while sending a POST request to a node.js API

I have a node.js API as below to which I send a POST request from python as below,the issue am facing is if I remove the headers={"Content-Type": "application/json"} the POST goes thorugh,if not i get a Read timed out. error, can anyone provide guidance on how to fix this timeout error ?

node.js endpoint

app.post("/api/bats_push",(req, res) => {
        //console.log("Calling bats_push...")
        const d = {
            method: req.method,
            headers: req.headers,
            query: req.query,
            body: ''
        }

        req.on('data', (c) => {
            //console.log(c)
            d.body = d.body + c
        });

        req.on('end', () => {
            DATA.push(d);
            res.end('Saved BATS job details');
            //res.status(200).json({
              //message: "Saved BATS job details",
              //posts: req.body
          //}); 
        });
});

Python POST

try:
json"},timeout=10.0)
    r = requests.post(webhook_url,data=json_data.encode("utf8"),verify=False,headers={"Content-Type": "application/json"})
    print "posted"
    print(r.status_code, r.reason)
    print r.url
    print r.text
except Exception as e:
    print (e)

Error:-

  InsecureRequestWarning)
HTTPSConnectionPool(host='company.com', port=443): Read timed out. (read timeout=10.0)


from Read timed out. error while sending a POST request to a node.js API

No comments:

Post a Comment