I am Trying to set up a simple Node.Js Server which calls a Python Script on hitting a url. Given below are the python and Node js server file.
When I hit the server url. The page loads! but then the server crashes and It give me the following error (in the cmd prompt):
Server listening on: http://localhost:8080/
this is here so we are in
events.js:141
throw er; // Unhandled 'error' event
^
Error: spawn C:UsersShubhamAnaconda3libos.py ENOENT
at exports._errnoException (util.js:837:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:178:32)
at onErrorNT (internal/child_process.js:344:16)
at doNTCallback2 (node.js:429:9)
at process._tickCallback (node.js:343:17)
and this in the Web browser console:
GET http://localhost:8080/favicon.ico net::ERR_CONNECTION_REFUSED
I have checked similar issues. But they are a little different and their fixes don't help me. I HAVE CLEARED THE CACHE AND CHECKED.
Python file:
import sys
def runForFun(artist, song, lyrics):
if lyrics is None:
print("artist:" + artist)
print("song:"+song)
print("lyrics:"+lyrics)
theme = "theme"
return theme
else :
print("lyrics: "+lyrics)
try:
runForFun(sys.argv[0], sys.argv[1], sys.argv[2])
except IndexError:
print('Please supply arguments')
Node js file
//Lets require/import the HTTP module
var http = require('http');
var PythonShell = require('python-shell');
//Lets define a port we want to listen to
const PORT=8080;
//We need a function which handles requests and send response
function handleRequest(request, response){
var options = {
mode: 'text',
pythonPath: 'C:\Users\Shubham\Anaconda3\lib\os.py',
pythonOptions: ['-u'],
scriptPath: 'C:\Users\Shubham\Google Drive\Capstone\Theme Extraction',
args: ['value1', 'value2', 'value3']
};
console.log("this is here so we are in");
PythonShell.run('runPython.py', options, function (err, results) {
if (err) throw err;
console.log('results: %j', results, 'finished');
});
response.end('It Works!! Path Hit: ' + request.url);
}
//Create a server
var server = http.createServer(handleRequest);
//Lets start our server
server.listen(PORT, function(){
//Callback triggered when server is successfully listening. Hurray!
console.log("Server listening on: http://localhost:%s/", PORT);
});
Error: spawn C:UsersShubhamAnaconda3libos.pyDoes that look like a file path? You likely need to escape the backslashespythonPathneeds to point at the python executable file, not a python script.var optionsin your code something that is internal? You needC:\\Users, for examplevar optionswhere you have unescaped backslashes atpythonPath: 'C:\Users\Shubham\Anaconda3\lib\os.py'