[英]Running python script in IBM Watson node.js chatbot
I made a chatbot in Node.js with IBM Watson. 我使用IBM Watson在Node.js中创建了一个聊天机器人。 I'm trying to run a python script in it but I'm not able to.
我正在尝试在其中运行python脚本,但无法执行。 I tried browserify and bundled up all dependencies in a .js file and called the script in the html page but still it isn't working.
我尝试使用browserify并将所有依赖项捆绑在一个.js文件中,并在html页中调用了该脚本,但仍然无法正常工作。
var PythonShell = require('python-shell');
var options = {
mode: 'text',
args: 765
};
PythonShell.run('pyt.py', options, function (err, results) {
if (err) throw err;
console.log('results: %j', results[0].toString());
});
It's running on locally between a node.js and a python file. 它在node.js和python文件之间本地运行。 But, doesn't work when I deploy the chatbot on a server.
但是,当我在服务器上部署chatbot时,它不起作用。
If you want to use the data returned from the Python script, you should use in your python script, try to put it: 如果要使用从Python脚本返回的数据,则应在python脚本中使用,请尝试将其放入:
print(dataToSendBack)
sys.stdout.flush()
And then Node can check your data with: 然后Node可以使用以下命令检查您的数据:
var spawn = require("child_process").spawn;
var pythonProcess = spawn('python',["path/to/script.py", arg1, arg2, ...]);
pythonProcess.stdout.on('data', function (data){
// Do something with the data returned from python script
});
child-process
. child-process
更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.