0

I use a mod_python publisher function which calls the main() function of another python script with a custom built argv list. When I execute the publisher script from shell command line it works. But when I tried it through apache2 with mod_python, I get the error (shown below) that main takes no arguments.


File "/var/www/wabaServ/waba.py", line 15, in index
    aba.main([ "aba.py","-i", "-b"])

TypeError: main() takes no arguments (1 given)

main() in aba.py is defined as:

def main(argv=None):
 --code--

Note: if the list argument is not passed, aba.main() gets executed from mod_python.

The mod_python publisher function looks like:

import sys
sys.path.append("/u/scripts")
import aba
from cStringIO import StringIO

def index():

    old_stdout = sys.stdout
    sys.stdout = mystdout = StringIO()
    aba.main([ "aba.py","-i", "-b"])
    sys.stdout = old_stdout
    return(mystdout.getvalue())
Anthon
  • 69,918
  • 32
  • 186
  • 246
  • 1
    There has to be some other code (presumably in `aba.py`) that alters the binding of its `main` -- otherwise the symptoms you describe would be impossible. – Alex Martelli Dec 22 '09 at 02:40
  • Or you have a configuration issue in `mod_python`, and you're not actually running what you claim to be running. Please dump `sys.path` to a logging file to confirm that you're really running what you think you should be running. – S.Lott Dec 22 '09 at 03:21

1 Answers1

0

The first logging statement says:

aba.main([ "aba.py","-i", "-b"])

And you say main is defined as:

def main(argv=None):

Therefore aba is passed in as the first argument into main() which takes up the argv argument and then there's no arguments left to pass that list in.

I don't think this has anything to do with mod_python.

Tim Tisdall
  • 9,914
  • 3
  • 52
  • 82