错误:在ubuntu中为尝试运行python的node.js / express app生成EACCES

时间:2016-08-05 11:34:41

标签: javascript python node.js ubuntu express

我已经使用python-shell 创建了一个node.js服务器来运行python脚本,并且自从从Windows迁移到Ubuntu后,我遇到了一个EACCES错误。我有我的知识和有限的能力尝试设置正确的权限无济于事,并且目前没有发现任何有问题的人,如服务器试图运行另一个脚本。我的问题是如何阻止发生这样的错误?

编辑:添加了JavaScript代码,主服务器文件夹中ls-l的图像和js脚本文件夹。

表达HTML错误日志(已修改):

this.items.forEach((item,index)=>{
  item=this.func(item,index);
})

func(item,index):string{
    return item+ String(index); //do whatever you wish to do.
}

Javascript代码:

<h1>spawn EACCES</h1>
<h2></h2>
<pre>Error: spawn EACCES
    at exports._errnoException (util.js:870:11)
    at ChildProcess.spawn (internal/child_process.js:298:11)
    at exports.spawn (child_process.js:362:9)
    at new PythonShell (/home/user_name/simple_server/node_modules/python-shell/index.js:59:25)
    at run_py_script (/home/user_name/simple_server/routes/rain_track.js:11:19)
    at /home/user_name/simple_server/routes/rain_track.js:43:5
    at Layer.handle [as handle_request] (/home/user_name/simple_server/node_modules/express/lib/router/layer.js:95:5)
    at next (/home/user_name/simple_server/node_modules/express/lib/router/route.js:131:13)
    at Route.dispatch (/home/user_name/simple_server/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/home/user_name/simple_server/node_modules/express/lib/router/layer.js:95:5)</pre>

var express = require('express'); var router = express.Router(); var PythonShell = require('python-shell'); var options = { mode: 'json', pythonPath: '/home/user_name/simple_server' }; function run_py_script(data, res, callback){ var pyshell = new PythonShell('dummy.py', options); console.log(data.latitude + ", " + data.longitude + "\n"); pyshell.send(""+data.latitude + ", "+ data.longitude+"\n"); // change to data pyshell.on('message', function(message){ console.log(message); res.json(message); }); pyshell.end(function(err){ if (err) { console.log("Python script error has occured."); console.log(err); } //return err ? callback(null) : callback(null, ret_val); }); } /* GET rain_track data. */ router.post('/', function(req, res, next) { console.log("Location got: "+req.body.coords.latitude + ", " + req.body.coords.longitude); var location_data = { "latitude" : req.body.coords.latitude, "longitude" : req.body.coords.longitude }; run_py_script(location_data, res, function(err, rain_data) { if (err){ console.log("error in python script" ); return res.json(null); } }) }); module.exports = router;

ls -l of directories

1 个答案:

答案 0 :(得分:0)

经过详细的测试,我一直无法找到解决这个问题的方法,问题确实已经死了。

然而,我成功找到了解决办法,发现EACCES的问题在于python路径(在options对象中)。删除它并在服务器终端的运行位置(例如/bin目录)中运行python脚本仍然可以正常工作。