[2.4.3/Newbie] Web script doesn't run

G

Gilles

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.
 
G

Gilles

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").
 
C

Chris Angelico

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
 
G

Gilles

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.
 
C

Chris Angelico

Good to know.


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
 
G

Gilles

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.
 
C

Chris Angelico

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
 
G

Gilles

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top