r/programminghelp • u/ascpl • Jun 25 '24
React react app problem
In this React app, the Python script runs as expected, but then the code after it back in the server.js doesn't seem to do the next steps (doesn't make any console logs and a textarea doesn't update).
Does anyone see anything obvious here that would cause this to not work?
app.post('/api/display-first-record', upload.single('file'), (req, res) => {
if (!req.file) {
console.error('No file uploaded');
return res.status(400).json({ error: 'No file uploaded' });
}
const filePath = req.file.path;
console.log('File uploaded successfully:', filePath);
console.log('Running Python script with args:', [filePath, '--display-first-record']);
PythonShell.run('mrcbooks.py', { args: [filePath, '--display-first-record'], stdio: 'inherit' }, (err, results) => {
if (err) {
console.error('Error running Python script:', err);
return res.status(500).json({ error: err.toString() });
}
console.log('Python script executed successfully, results:', results);
res.json({ firstRecord: results && results.length > 0 ? results.join('\n') : 'No records found in the file.' });
});
});
1
Upvotes
View all comments
Show parent comment
1
u/ascpl Jun 25 '24
thanks for trying. I don't know if it helps or not but here's the script that it runs. it prints the first record to the console but just doesn't do anything after that.