[2.4.3/Newbie] Web script doesn't run

Discussion in 'Python' started by Gilles, Feb 11, 2013.

  1. Gilles

    Gilles Guest

    Hello

    I have a couple of newbie questions about using Python in a FastCGI
    + Flup context on a shared CentOS server:

    1. The following script runs fine...
    =========================
    #!/usr/bin/env python2.6

    def myapp(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/plain')])
    return ['Done!\n']

    if __name__ == '__main__':
    from flup.server.fcgi import WSGIServer
    WSGIServer(myapp).run()
    =========================

    .... while this triggers an error:
    =========================
    #!/usr/bin/env python2.6
    # -*- coding: UTF-8 -*-

    from cgi import escape
    import sys, os

    def app(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/html')])

    yield '<h1>FastCGI Environment</h1>'
    yield '<table>'
    for k, v in sorted(environ.items()):
    yield '<tr><th>%s</th><td>%s</td></tr>' % (escape(k),
    escape(v))
    yield '</table>'

    if __name__ == '__main__':
    from flup.server.fcgi import WSGIServer
    WSGIServer(app).run()
    =========================

    "Internal Server Error: The server encountered an internal error or
    misconfiguration and was unable to complete your request. [...]
    Additionally, a 404 Not Found error was encountered while trying to
    use an ErrorDocument to handle the request."

    2. Generally speaking, what is the right way to investigate an error
    in a Python web script? FWIW I have access to the shared server
    through SSH.

    Thank you.
    Gilles, Feb 11, 2013
    #1
    1. Advertising

  2. Gilles

    Gilles Guest

    On Mon, 11 Feb 2013 10:30:01 +0100, Gilles <> wrote:
    > I have a couple of newbie questions about using Python in a FastCGI
    >+ Flup context on a shared CentOS server:


    Please ignore the thread. I found the error, and a way to catch
    compile-time errors (log on through SSH, and run "python
    ../myscript.py").
    Gilles, Feb 11, 2013
    #2
    1. Advertising

  3. On Mon, Feb 11, 2013 at 8:39 PM, Gilles <> wrote:
    > On Mon, 11 Feb 2013 10:30:01 +0100, Gilles <> wrote:
    >> I have a couple of newbie questions about using Python in a FastCGI
    >>+ Flup context on a shared CentOS server:

    >
    > Please ignore the thread. I found the error, and a way to catch
    > compile-time errors (log on through SSH, and run "python
    > ./myscript.py").


    That'll catch some forms of error, but not everything. You may also
    want to consider looking for your server's error log - that may be
    getting the actual traceback. I don't know what your server setup is,
    but there's likely to be one somewhere.

    A question though. You say "2.4.3" in your subject line, but your
    shebang says python2.6 - which version are you actually running? At
    very least, I'd recommend using python2.6 to run your script from the
    shell; if there's any incompatibility between the system Python (which
    quite plausibly would be the 2.4.3 you named) and the one your CGI
    script uses (named python2.6 and my guess would be that it's 2.6.6),
    you'll confuse yourself when you do your "shell test".

    ChrisA
    Chris Angelico, Feb 11, 2013
    #3
  4. Gilles

    Gilles Guest

    On Mon, 11 Feb 2013 21:30:12 +1100, Chris Angelico <>
    wrote:
    >That'll catch some forms of error, but not everything. You may also
    >want to consider looking for your server's error log - that may be
    >getting the actual traceback. I don't know what your server setup is,
    >but there's likely to be one somewhere.


    Good to know.

    >A question though. You say "2.4.3" in your subject line, but your
    >shebang says python2.6 - which version are you actually running?


    I didn't pay attention to this. Support says that I should use 2.6,
    but running "python -V" through SSH says 2.4.3. I'll ask support which
    to use.

    Thank you.
    Gilles, Feb 11, 2013
    #4
  5. On Mon, Feb 11, 2013 at 10:22 PM, Gilles <> wrote:
    > On Mon, 11 Feb 2013 21:30:12 +1100, Chris Angelico <>
    > wrote:
    >>That'll catch some forms of error, but not everything. You may also
    >>want to consider looking for your server's error log - that may be
    >>getting the actual traceback. I don't know what your server setup is,
    >>but there's likely to be one somewhere.

    >
    > Good to know.
    >
    >>A question though. You say "2.4.3" in your subject line, but your
    >>shebang says python2.6 - which version are you actually running?

    >
    > I didn't pay attention to this. Support says that I should use 2.6,
    > but running "python -V" through SSH says 2.4.3. I'll ask support which
    > to use.


    Try running python2.6 -V

    Your shebang line says that it's looking for a program named
    "python2.6", which is quite probably not the same as the one named
    just "python".

    ChrisA
    Chris Angelico, Feb 11, 2013
    #5
  6. Gilles

    Gilles Guest

    On Mon, 11 Feb 2013 22:30:45 +1100, Chris Angelico <>
    wrote:
    >Try running python2.6 -V
    >
    >Your shebang line says that it's looking for a program named
    >"python2.6", which is quite probably not the same as the one named
    >just "python".


    Indeed, they have two versions of Python installed:

    # python2.6 -V
    Python 2.6.4

    # python -V
    Python 2.4.3

    I'll make sure to use 2.6.

    Thank you.
    Gilles, Feb 11, 2013
    #6
  7. On Mon, Feb 11, 2013 at 10:36 PM, Gilles <> wrote:
    > On Mon, 11 Feb 2013 22:30:45 +1100, Chris Angelico <>
    > wrote:
    >>Try running python2.6 -V
    >>
    >>Your shebang line says that it's looking for a program named
    >>"python2.6", which is quite probably not the same as the one named
    >>just "python".

    >
    > Indeed, they have two versions of Python installed:
    >
    > # python2.6 -V
    > Python 2.6.4
    >
    > # python -V
    > Python 2.4.3
    >
    > I'll make sure to use 2.6.


    It's entirely possible you have a third Python, a 3.x, as well.
    Different Pythons coexist quite happily on a system.

    Anyway, seems your issue's sorted out. Yay!

    ChrisA
    Chris Angelico, Feb 11, 2013
    #7
  8. Gilles

    Gilles Guest

    On Mon, 11 Feb 2013 22:42:50 +1100, Chris Angelico <>
    wrote:
    >It's entirely possible you have a third Python, a 3.x, as well.
    >Different Pythons coexist quite happily on a system.


    Thank for the help. I'm on my way to figure out how mod_fcgid, Flup,
    and Python scripts work together.
    Gilles, Feb 11, 2013
    #8
    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. VB Programmer
    Replies:
    1
    Views:
    613
    VB Programmer
    Jan 26, 2006
  2. Replies:
    5
    Views:
    463
  3. Replies:
    1
    Views:
    323
    Larry Bates
    Dec 14, 2006
  4. Replies:
    9
    Views:
    948
    Paddy O'Loughlin
    Feb 27, 2009
  5. jackster the jackle

    Error Exception if script doesn't run

    jackster the jackle, Oct 17, 2008, in forum: Ruby
    Replies:
    19
    Views:
    173
    Nobuyoshi Nakada
    Oct 22, 2008
Loading...

Share This Page