在Rails应用程序

时间:2016-01-20 16:52:46

标签: python ruby-on-rails ruby

我有一个python脚本(程序),我必须从我的Ruby on Rails应用程序执行。我可以使用以下命令从我的gnome终端(UNIX)执行它:

setsid python /path-to-app-directory/api.py 8080 >>python_api.log 2>&1

它工作正常。这样的执行使得API服务在localhost,端口8080上启动,然后我可以在那里发送不同的请求,并且它的响应非常快。

现在,我的任务是将它集成到我自己的应用程序中 - 在我的Rails应用程序中启动这样的服务。但是在执行命令时

system('setsid python /path-to-app-directory/api.py 8080 >>python_api.log 2>&1')

我收到此错误:

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

并且服务未启动。

我也尝试过Ruby提供的其他可能的方法来执行这种命令,例如:使用backsticks,exec()方法或spawn()方法。但在这两种情况下都会出现同样的错误。

经过一些研究,似乎python脚本在从另一个进程(shell)调用时缺少某些模块,因为这些参数通常是从OS环境变量接收的。更多关于这个主题: WSGIServer errors when trying to run Django app

没有Python编程的经验,我很感激你解决这个问题的任何帮助。

事先谢谢你。

0 个答案:

没有答案