为什么我不能通过网络服务器使用 subprocess 模块执行另一个 python 脚本 [英] Why can't I execute another python script using the subprocess module via a webserver
问题描述
调用另一个脚本时遇到问题,顺便说一下,当我只调用 python main.py(然后调用 test3.py)时它在控制台上工作正常,但是当我通过网络服务器执行它时,它给出了以下错误神秘的
Having a problem envoking another script, by the way it works fine from the console when I just call python main.py (which then calls test3.py) but when I do it via the webserver it gives the error below which is cryptic
我不能称之为(test3 只是一个打印...)
I can't call this (test3 is just a print...)
#proc = subprocess.Popen(['python', 'test3.py'], stdout=subprocess.PIPE)
但这很好用
proc = subprocess.Popen(['ls', '-la'], stdout=subprocess.PIPE)
在 FreeBSD 上登录/var/log/httpd-error.log 时出错
Error Log in /var/log/httpd-error.log on FreeBSD
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61] Traceback (most recent call last):
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61] File "/usr/local/www/apache22/data/main2.py", line 22, in <module>
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61]
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61] proc = subprocess.Popen(['python', 'test3.py'], stdout=subprocess.PIPE)
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61] File "/usr/local/lib/python2.7/subprocess.py", line 679, in __init__
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61]
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61] errread, errwrite)
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61] File "/usr/local/lib/python2.7/subprocess.py", line 1228, in _execute_child
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61]
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61] raise child_exception
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61] OSError
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61] :
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61] [Errno 2] No such file or directory
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61]
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61] File does not exist: /usr/local/www/apache22/data/favicon.ico
推荐答案
python
可执行文件不在网络服务器中 可执行路径.网络服务器也可能使用 chroot 或类似技术进行保护,因此无法访问 python 安装.
The python
executable is not in the webservers executable PATH. The webserver may also be secured with a chroot or similar techniques and therefore be unable to access the python installation.
尝试指定 python 可执行文件的完整路径(您可以使用 which
命令),像这样:
Try specifying the full path of the python executable (you can find it out interactively with the which
command), like this:
proc = subprocess.Popen(['/usr/bin/python', 'test3.py'], stdout=subprocess.PIPE)
这篇关于为什么我不能通过网络服务器使用 subprocess 模块执行另一个 python 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!