首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >从python-shell返回值作为响应

从python-shell返回值作为响应
EN

Stack Overflow用户
提问于 2018-07-30 13:42:11
回答 3查看 1.2K关注 0票数 0

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

代码语言:javascript
运行
复制
Can't set headers after they are sent.

以下是我的代码

代码语言:javascript
运行
复制
app.post('/therun', (req, res)=>{

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

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

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

      });

       res.send(message); //if i use here message undefined


});

如何解决这个问题?

EN

Stack Overflow用户

发布于 2018-07-30 14:06:16

代码语言:javascript
运行
复制
    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


});

你能告诉我在你的控制台上对test值的回应吗?

票数 1
EN
查看全部 3 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51587602

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档