How to correctly send a CSV file from Express.js to Python code?

Viewed 125

I have read this code but an error is coming. I am trying to send a read CSV file from Express.js to Python but getting an error.

The error is:

events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: read ECONNRESET
    at _errnoException (util.js:1022:11)
    at Pipe.onread (net.js:628:25) 

Here is my Python code:

import sys
print(sys.stdin)
filename = sys.stdin.read()
read_DataChunks(filename))# to read filename and process data

Here is my Express code:

router.post("/Postapi",(req,res)=>{

    upload(req,res,(err)=>{

        if (!req.file){
            return res.json({file:"Did you Upload FIle? Go back and upload File"})
        }
        if(err){
            return res.status(500).send({error:err.message});
        }
    
   
        let pyShelll = new PythonShell("./pythonScripts/MCAGov.py",{mode:"text"})

        fs.createReadStream("./uploads/"+req.file.filename)// file goes to upload folder ,is it correct?
        .pipe(csv())
        .on('data', (row) => {
            pyShelll.send(row)
        });

        res.render("hander")
    })

    // res.json({message:"Sent"})
})
0 Answers
Related