Hi, I am working on a nodeJS application and I want to integrate a python script, as expected it works locally but returns an error as: {"error":"Command failed: python3 fetch_stock_data.py AAPL 3mo 1d /bin/sh: line 1: python3: command not found "} for GET request to the backend.
It should rather give me a response from the python script and then display the data on the frontend.
This is the server code: // Endpoint to fetch stock data router.get("/history", async (req, res) => { const { symbol = "AAPL", period = "3mo", interval = "1d" } = req.query;
try {
exec(
python3 fetch_stock_data.py ${symbol} ${period} ${interval},
(error, stdout, stderr) => {
if (error) {
console.error(Error: ${error.message});
return res.status(500).json({ error: error.message });
}
if (stderr) {
console.error(Stderr: ${stderr});
return res.status(500).json({ error: stderr });
}
// Send the output as the response try { const parsedOutput = JSON.parse(stdout); res.json(parsedOutput); } catch (parseError) { res .status(500) .json({ error: "Failed to parse Python script output" }); } });} catch (error) { console.error("Error in /history route:", error); res.status(500).json({ error: "Internal Server Error" }); } });
And the error is mentioned above.
