Strange behavior with os call in cgi script

Discussion in 'Python' started by sophie_newbie, Feb 5, 2006.

  1. I have written a cgi script that seems to run perfectly from the
    command line when I simulate some cgi input using
    os.environ['QUERY_STRING'].

    The thing is that when I run it from the browser, one of my os.system
    calls, which gets excecuted fine when running the program in the
    interpreter, doesn't seem to get excecuted, or gets excecuted but does
    nothing.

    Does anyone know whats going on or how I could debug this problem?

    It is worth noting that other os.system calls in the script get
    excecuted fine.
     
    sophie_newbie, Feb 5, 2006
    #1
    1. Advertising

  2. sophie_newbie schrieb:
    > I have written a cgi script that seems to run perfectly from the
    > command line when I simulate some cgi input using
    > os.environ['QUERY_STRING'].
    >
    > The thing is that when I run it from the browser, one of my os.system
    > calls, which gets excecuted fine when running the program in the
    > interpreter, doesn't seem to get excecuted, or gets excecuted but does
    > nothing.
    >
    > Does anyone know whats going on or how I could debug this problem?
    > [...]


    Probably the environment is different when your program is executed by
    your web server. So either PATH is wrong and your program is not found
    or some other environment variable is wrong and you could debug it by
    printing the environment in your program.
     
    Dennis Benzinger, Feb 5, 2006
    #2
    1. Advertising

  3. OK, interesting, but just how dow I print he environment in the
    program??
     
    sophie_newbie, Feb 5, 2006
    #3
  4. sophie_newbie

    Rene Pijlman Guest

    Rene Pijlman, Feb 5, 2006
    #4
  5. sophie_newbie

    Steve Holden Guest

    Rene Pijlman wrote:
    > sophie_newbie:
    >
    >>OK, interesting, but just how dow I print he environment in the
    >>program??

    >
    >
    > Add logging to your program:
    > http://www.python.org/doc/2.3.5/lib/module-logging.html
    >

    Probably oiverkill, particularly for a beginner (is it only me that
    thinks the logging module is either way over-complicated or way
    under-documented?).

    > And log the environment:
    > http://www.python.org/dev/doc/newstyle/lib/os-procinfo.html
    >


    regards
    Steve
    --
    Steve Holden +44 150 684 7255 +1 800 494 3119
    Holden Web LLC www.holdenweb.com
    PyCon TX 2006 www.python.org/pycon/
     
    Steve Holden, Feb 6, 2006
    #5
  6. sophie_newbie

    Duncan Booth Guest

    Steve Holden wrote:

    >> Add logging to your program:
    >> http://www.python.org/doc/2.3.5/lib/module-logging.html
    >>

    > Probably oiverkill, particularly for a beginner (is it only me that
    > thinks the logging module is either way over-complicated or way
    > under-documented?).


    No, I would agree with you on that. I get the impression that it was
    designed by studying some pre-existing logging packages and saying 'what
    neat features can we take from each of these' rather than by writing up a
    set of use-cases and saying 'what is the simplest way we can make all of
    these possible'.

    The way it is now means there is quite a step from the simplest possible
    use to slightly more complex use. For example, the support for reading
    configuration files is wonderfully general purpose, but far too much for
    the vast majority of applications: you really don't want to expose a
    typical end user to that sort of configuration soup. If all you want in
    your application is to let the user specify the name of the logfile and the
    logging level you are on your own (and you can't even convert the log level
    name from a string to the required number without accessing an _ prefixed
    variable in the logging module).
     
    Duncan Booth, Feb 6, 2006
    #6
  7. sophie_newbie

    Rene Pijlman Guest

    Steve Holden:
    >Rene Pijlman:
    >> Add logging to your program:
    >> http://www.python.org/doc/2.3.5/lib/module-logging.html
    >>

    >Probably oiverkill, particularly for a beginner (is it only me that
    >thinks the logging module is either way over-complicated or way
    >under-documented?).


    It struck me as somewhat complicated as well.

    Looking at the basic example:
    http://www.python.org/doc/2.3.5/lib/node304.html

    .... the things that first-time users shouldn't be bothered with IMO are:

    1. Getting a logger by name from a hierarchical namespace. There should be
    a module-level log function that logs through the root logger.
    2. Formatting the message (use a sensible default)
    3. Adding a handler to a logger (artefact of the logging system).
    4. Setting a log level (use a sensible default).

    Perhaps there should be some module-level functions that make it easier to
    'just log this message to that file'.

    But I do think that adding logging to a cgi script is a sensible thing to
    do for a beginner. Getting that to run in a debugger is probably way more
    complicated.

    --
    René Pijlman
     
    Rene Pijlman, Feb 6, 2006
    #7
  8. Rene Pijlman wrote:

    > But I do think that adding logging to a cgi script is a sensible thing to
    > do for a beginner. Getting that to run in a debugger is probably way more
    > complicated.


    on the other hand, adding

    if 1: # set to 0 when deploying
    print "<pre>"
    print cgi.escape(repr(os.environ))
    print "</pre>"

    to the CGI script isn't that hard... (if you're willing to do "view source" in
    the browser, you can skip the <pre> and cgi.escape() stuff...)

    </F>
     
    Fredrik Lundh, Feb 6, 2006
    #8
  9. sophie_newbie

    Jim Guest

    > But I do think that adding logging to a cgi script is a sensible thing to
    > do for a beginner.

    Let me second that. I happen to write a lot of CGI, and ISTM that
    while you can do it without logging, you are condemming yourself to a
    lot of staring at the screen, head-scratching, and saying ``Now what
    could *that* mean?'' That is, CGI programming without logging seems to
    me to ba a lot like general programming in Perl. :-}

    Jim
     
    Jim, Feb 7, 2006
    #9
  10. sophie_newbie

    Vinay Sajip Guest

    Rene Pijlman wrote:
    > It struck me as somewhat complicated as well.
    >
    > Looking at the basic example:
    > http://www.python.org/doc/2.3.5/lib/node304.html
    >
    > ... the things that first-time users shouldn't be bothered with IMO are:
    >
    > 1. Getting a logger by name from a hierarchical namespace. There should be
    > a module-level log function that logs through the root logger.
    > 2. Formatting the message (use a sensible default)
    > 3. Adding a handler to a logger (artefact of the logging system).
    > 4. Setting a log level (use a sensible default).
    >
    > Perhaps there should be some module-level functions that make it easier to
    > 'just log this message to that file'.
    >
    > But I do think that adding logging to a cgi script is a sensible thing to
    > do for a beginner. Getting that to run in a debugger is probably way more
    > complicated.


    You should look at later versions of Python - your points above about
    easier configuration have already been addressed: here's a link from
    the current (2.4) docs:

    http://docs.python.org/lib/minimal-example.html

    Regards,

    Vinay Sajip
     
    Vinay Sajip, Feb 7, 2006
    #10
  11. sophie_newbie

    Rene Pijlman Guest

    Vinay Sajip:
    >Rene Pijlman:
    >> It struck me as somewhat complicated as well.


    >You should look at later versions of Python - your points above about
    >easier configuration have already been addressed: here's a link from
    >the current (2.4) docs:
    >
    >http://docs.python.org/lib/minimal-example.html


    Yes, that looks good. Thanks for pointing that out. So... my advice to OP
    (if still alive) is:

    Add logging to your program:
    http://docs.python.org/lib/minimal-example.html

    And log the environment:
    http://www.python.org/dev/doc/newstyle/lib/os-procinfo.html

    :)

    --
    René Pijlman
     
    Rene Pijlman, Feb 8, 2006
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. praba kar

    Python-cgi or Perl-cgi script doubt

    praba kar, Jul 30, 2005, in forum: Python
    Replies:
    1
    Views:
    810
    Michael Sparks
    Jul 30, 2005
  2. Amir  Michail

    cgi relay for python cgi script

    Amir Michail, Oct 4, 2005, in forum: Python
    Replies:
    7
    Views:
    493
    Michael Ekstrand
    Oct 4, 2005
  3. oerz

    Strange behavior of DropDownList after function call

    oerz, Jul 5, 2004, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    242
    Teemu Keiski
    Jul 6, 2004
  4. Benoit Fries
    Replies:
    1
    Views:
    85
    Thomas 'PointedEars' Lahn
    Nov 14, 2003
  5. kath
    Replies:
    4
    Views:
    812
    J. Gleixner
    Apr 9, 2007
Loading...

Share This Page