I have got a python script(program) that I have to execute from my Ruby on Rails application. I can execute it from my gnome terminal(UNIX) using this command:
setsid python /path-to-app-directory/api.py 8080 >>python_api.log 2>&1
And it works fine. Such an execution makes an API service be started on localhost, port 8080, where I can then send different requests and it responses really quickly.
Now, my task is to integrate it in my own app - start such a service inside my Rails application. But when executing command
system('setsid python /path-to-app-directory/api.py 8080 >>python_api.log 2>&1')
I get this error:
WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI!
WSGIServer: missing FastCGI param SERVER_NAME required by WSGI!
WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!
Status: 404 Not Found
Content-Type: text/html
and the service is not started.
I have tried also with the other possible methods that Ruby offers for executing this kind of commands, like: using backsticks, exec() method or spawn() method. But the same error occurs in both cases.
After some research, it seems like python script is missing some modules when called from another process(shell), as these parameters would usually be received from the OS Environment Variables. More on this topic: WSGIServer errors when trying to run Django app
Having got no prior experience with Python programming, I would appreciate any help in solving this.
Thank you beforehand.