2

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

I can't call this (test3 is just a print...)

#proc = subprocess.Popen(['python', 'test3.py'], stdout=subprocess.PIPE)

but this works fine

proc = subprocess.Popen(['ls', '-la'], stdout=subprocess.PIPE)

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
Sean Cav
  • 133
  • 1
  • 14

2 Answers2

2

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.

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)
phihag
  • 278,196
  • 72
  • 453
  • 469
  • This was it! I missed this b/c I though my path was already correct (I can type python on the console line and python comes up), but it is indeed incorrect for the webserver! Not sure how this is different I will have to do some reading. Suggestions for place to do this on freeBSD is helpful. My path is actually /usr/local/bin/python on FreeBSD! Works like a charm... i typing so long b/c it won't let me click the check mark yet.... 20 seconds... ok lets do this – Sean Cav Mar 01 '12 at 17:48
0
  1. Could you directly import your test3 code in to the project instead of calling it through the OS?

  2. Are your relative paths all correct? It kind of sounds like you might be running something from the wrong directory or missing some needed files in the directory on the remote machine.

Silas Ray
  • 25,682
  • 5
  • 48
  • 63
  • Well I am going the subprocess route b/c of [this other problem I stated here](http://stackoverflow.com/questions/9507602/why-is-my-stdout-interfering-with-my-webpage-in-python) but when I do the ls -la it is showing up in the same directory... maybe I will make another test script and test it out just as a sanity check (test.py that just does a print)... – Sean Cav Mar 01 '12 at 17:43