WebFaction
Community site: login faq

Hello all, I'm writing a simple mod_wsgi webapp, and I need to pass command lines arguments to an R script I wrote. However I am getting a 500 error because python is not executing the os command. Here is an example of the code I am using:

import os
a=2
b=3 
commandString="R --no-save --quiet --slave --args " + str(a) + " " + str(b) + " <myscript.R"
os.system(commandString)

Is there a different python function that I should be using?

Thanks for your help

asked 22 Jul '12, 12:40

jahan
112
accept rate: 0%


What is the exact 500 error? It can be located within the logs defined in the apache httpd.conf file.

permanent link

answered 22 Jul '12, 17:21

johns
5.4k312
accept rate: 23%

Here is what I get in the error log, and I explain a bit below it:

 sh: R: command not found

[Mon Jul 23 16:19:57 2012] [error] [client 127.0.0.1] mod_wsgi (pid=13478): Exception occurred
processing WSGI script '/home/jahan/webapps/simple/htdocs/index.py'.

[Mon Jul 23 16:19:57 2012] [error] [client 127.0.0.1] Traceback (most recent call last):

[Mon Jul 23 16:19:57 2012] [error] [client 127.0.0.1]   File "/home/jahan/webapps/simple/htdocs/index.py", line 88, in application

[Mon Jul 23 16:19:57 2012] [error] [client 127.0.0.1]     f=open('/home/jahan/webapps/simple/htdocs/prob.txt','r')

[Mon Jul 23 16:19:57 2012] [error] [client 127.0.0.1] IOError: [Errno 2] No such file or directory: '/home/jahan/webapps/simple/htdocs/prob.txt'

[Mon Jul 23 16:19:57 2012] [error] [client 127.0.0.1] File does not exist: /home/jahan/webapps/simple/htdocs/favicon.ico

The R script that I want python to execute writes a .txt file, which python then reads later in the index.py script. I am getting the "No such file" error because the R script isn't writing the file in the first place (since it's not getting called).

(23 Jul '12, 11:27) jahan

R isn't installed globally, and you can't assume that mod_wsgi will be using the PATH from your shell environment, so I suspect that you might need to use the full path to R, for example /home/you/bin/R, when invoking it from your application.

permanent link

answered 23 Jul '12, 08:13

seanf
12.2k41836
accept rate: 37%

Ok that makes sense, but when I changed it to the full path I'm still getting a 500 error. Here is what I got from the error log:

[Mon Jul 23 16:33:26 2012] [error] [client 127.0.0.1] mod_wsgi     (pid=13549): Exception occurred processing WSGI script     '/home/jahan/webapps/simple/htdocs/index.py'.

[Mon Jul 23 16:33:26 2012] [error] [client 127.0.0.1] Traceback     (most recent call last):

[Mon Jul 23 16:33:26 2012] [error] [client 127.0.0.1]   File     "/home/jahan/webapps/simple/htdocs/index.py", line 88, in application

[Mon Jul 23 16:33:26 2012] [error] [client 127.0.0.1]         f=open('/home/jahan/webapps/simple/htdocs/prob.txt','r')

[Mon Jul 23 16:33:26 2012] [error] [client 127.0.0.1] IOError:     [Errno 2] No such file or directory:     '/home/jahan/webapps/simple/htdocs/prob.txt'

[Mon Jul 23 16:33:26 2012] [error] [client 127.0.0.1] File does     not exist: /home/jahan/webapps/simple/htdocs/favicon.ico
(23 Jul '12, 11:35) jahan

Did you restart apache after updating your code?

(23 Jul '12, 11:39) seanf

I'm a novice to web development; what exactly do you mean by restarting apache?

(23 Jul '12, 11:54) jahan

Your WSGI application runs on a private Apache instance that must be restarted to pick up changes to your code. Base on the info you've provided, the command to restart it would be "~/webapps/simple/apache2/bin/restart".

(23 Jul '12, 13:36) seanf
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×337
×62
×54
×16

question asked: 22 Jul '12, 12:40

question was seen: 4,054 times

last updated: 23 Jul '12, 13:36

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM