python-shell 来自节点应用程序

python-shell from a node application

问题:

如何在我的节点应用程序中 运行 我的 python 脚本?

这个有效:

从命令行,我运行这个,它有效。

python generatePersonTerraform.py -s http://localhost:8080/api/person/239/exportPersonGeneration

在节点中不起作用的代码server.js

var PythonShell = require('python-shell');
...

var runPythonRoutine = function (request, response) {
    var PythonShell = require('python-shell');
    var options = {
        mode: 'text',
        pythonPath: 'python',
        pythonOptions: ['-s'],
        scriptPath: '.',
        args: ['http://localhost:8080/api/person/135/exportPersonGeneration']
    };
    PythonShell.run('generatePersonTerraform.py', options, function (err, results) {
       console.log(err);
    });
}

错误:

    at PythonShell.parseError (/root/my-app/node_modules/python-shell/index.js:191:17)
    at terminateIfNeeded (/root/my-app/node_modules/python-shell/index.js:98:28)
    at ChildProcess.<anonymous> (/root/my-app/node_modules/python-shell/index.js:89:9)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:194:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
  executable: 'python',
  options: [ '-s' ],
  script: 'generatePersonTerraform.py',
  args: [ 'http://localhost:8080/api/person/239/exportPersonGeneration' ],
  exitCode: 1 }

备注

我一直在尝试使用https://www.npmjs.com/package/python-shell

编辑 1

我将选项更改为:

var options = {
    mode: 'text',
    pythonPath: 'python',
    pythonOptions: [],
    scriptPath: '.',
    args: ['-s', 'http://localhost:8080/api/serviceType/135/exportPluginGeneration']
};

并收到此错误:

    at PythonShell.parseError (/root/my-app/node_modules/python-shell/index.js:191:17)
    at terminateIfNeeded (/root/my-app/node_modules/python-shell/index.js:98:28)
    at ChildProcess.<anonymous> (/root/my-app/node_modules/python-shell/index.js:89:9)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:194:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
  executable: 'python',
  options: null,
  script: 'generatePersonTerraform.py',
  args: 
   [ '-s',
     'http://localhost:8080/api/person/135/exportPersonGeneration' ],
  exitCode: 0 }

但是,它也 运行 并且有效,它只是停止了节点应用程序。所以,如果我弄清楚如何让它不失速,那我就很好了。 python 脚本似乎构建了它应该构建的所有文件。

'-s' 应该在 args,而不是 pythonOptions