作为respons从pythonshell返回值

2024-10-02 18:22:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用pythonshell在nodeJS上运行python。我需要返回pythonshelloutput作为响应。但是当我试图发送响应时,它显示了一个错误

Can't set headers after they are sent.

这是我的密码

^{pr2}$

怎么解决这个问题?在


Tags: 密码错误nodejscanaresentheadersset
3条回答

你忘了关闭python shell(之后pyshell.on上()):

pyshell.end(function (err) {
  if (err) throw err;
});

而不是作为

res.send(message); //error here

你能试着用下面给出的状态码发送同样的邮件吗?在

^{pr2}$

希望这有帮助!在

    app.post('/therun', (req, res)=>{

    var pyshell = new PythonShell('hello.py');
    var test={};

    pyshell.on('message', function (message) {

       console.log(message); //value is correct
       //res.send(message); //error here
      test=message;

      });
       console.log(test);
       res.send(message); //if i use here message undefined


});

你能告诉我你的控制台上对测试值的反应吗?在

相关问题 更多 >