I have a python code and I call it in nodejs.
The python code will print a sentence at different stage. After each print in python there is a sys.stdout.flush()
.
Now I use nodejs python shell
app.post('/', function (req, res) {
flag = req.body.flag;
options = {
mode: 'text',
args: [ '--flag='+flag]
};
pyshell = new PythonShell(myPythonScriptPath, options)
pyshell.on('message', function (message) {
resultText = `It's ${flag} degrees in ${message}!`;
res.render('index', {result: resultText, error: null});
console.log(message);
})
})
It returned only one sentence and after that there was an error:
Error: Can't set headers after they are sent
.
This worked fine if I do not use
resultText = `It's ${flag} degrees in ${message}!`;
res.render('index', {result: resultText, error: null});
and only use terminal. BUT it fails with a web page. Does anyone know how to solve this?