[英]python-shell from a node application
Question: 题:
How do I run my python script in my node app? 如何在节点应用程序中运行python脚本?
This works: 这有效:
From command line, I run this, and it works. 从命令行运行此命令,它可以正常工作。
python generatePersonTerraform.py -s http://localhost:8080/api/person/239/exportPersonGeneration
Code that does not work in Node server.js 在Node 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);
});
}
Error: 错误:
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 }
Note 注意
I have been trying to use https://www.npmjs.com/package/python-shell 我一直在尝试使用https://www.npmjs.com/package/python-shell
EDIT 1 编辑1
I changed the options to: 我将选项更改为:
var options = {
mode: 'text',
pythonPath: 'python',
pythonOptions: [],
scriptPath: '.',
args: ['-s', 'http://localhost:8080/api/serviceType/135/exportPluginGeneration']
};
and got this error: 并得到此错误:
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 }
But, it also ran and worked, it just stalls the node app. 但是,它也可以运行并起作用,只是使节点应用程序停滞了。 So, if I figure out how to make it not stall then I am all good.
因此,如果我弄清楚如何使其不失速,那我就很好。 The python script seems to build all the files it is supposed to.
python脚本似乎可以构建所有应有的文件。
'-s'
应该在args
,而不是pythonOptions
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.