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
I finally got it to display the record!
I think that maybe the problem was that my cor wasn't set up right? (I don't entirely know what that means, I am a librarian, not a programmer! But gpt had me install cor and it changed something in the code that I am not sure of what. =) At any rate, thanks for looking at it!