gpt4 book ai didi

javascript - 错误 : spawn EACCES in ubuntu for node. js/express 应用程序尝试运行 python

转载 作者:太空宇宙 更新时间:2023-11-03 16:17:45 25 4
gpt4 key购买 nike

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

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

Express HTML 错误日志(已修改):

<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>

Javascript代码:

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:

ls -l of directories

最佳答案

经过详细测试,我一直无法找到该问题的解决方案,并且该问题确实已经消失。

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

关于javascript - 错误 : spawn EACCES in ubuntu for node. js/express 应用程序尝试运行 python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38788280/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com