Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > [2.4.3/Newbie] Web script doesn't run

Reply
Thread Tools

[2.4.3/Newbie] Web script doesn't run

 
 
Gilles
Guest
Posts: n/a
 
      02-11-2013
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.
 
Reply With Quote
 
 
 
 
Gilles
Guest
Posts: n/a
 
      02-11-2013
On Mon, 11 Feb 2013 10:30:01 +0100, Gilles <(E-Mail Removed)> 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").
 
Reply With Quote
 
 
 
 
Chris Angelico
Guest
Posts: n/a
 
      02-11-2013
On Mon, Feb 11, 2013 at 8:39 PM, Gilles <(E-Mail Removed)> wrote:
> On Mon, 11 Feb 2013 10:30:01 +0100, Gilles <(E-Mail Removed)> 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
 
Reply With Quote
 
Gilles
Guest
Posts: n/a
 
      02-11-2013
On Mon, 11 Feb 2013 21:30:12 +1100, Chris Angelico <(E-Mail Removed)>
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.
 
Reply With Quote
 
Chris Angelico
Guest
Posts: n/a
 
      02-11-2013
On Mon, Feb 11, 2013 at 10:22 PM, Gilles <(E-Mail Removed)> wrote:
> On Mon, 11 Feb 2013 21:30:12 +1100, Chris Angelico <(E-Mail Removed)>
> 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
 
Reply With Quote
 
Gilles
Guest
Posts: n/a
 
      02-11-2013
On Mon, 11 Feb 2013 22:30:45 +1100, Chris Angelico <(E-Mail Removed)>
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.
 
Reply With Quote
 
Chris Angelico
Guest
Posts: n/a
 
      02-11-2013
On Mon, Feb 11, 2013 at 10:36 PM, Gilles <(E-Mail Removed)> wrote:
> On Mon, 11 Feb 2013 22:30:45 +1100, Chris Angelico <(E-Mail Removed)>
> 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
 
Reply With Quote
 
Gilles
Guest
Posts: n/a
 
      02-11-2013
On Mon, 11 Feb 2013 22:42:50 +1100, Chris Angelico <(E-Mail Removed)>
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run a python script as an exe and run a new process from it venutaurus539@gmail.com Python 9 02-27-2009 05:22 PM
Error when python script run as cgi script sophie_newbie Python 3 10-22-2007 05:39 PM
Run ant script from ant script? lionelv@gmail.com Java 6 07-26-2007 02:12 AM
run a script and supply commands from a python cgi script moishyyehuda@gmail.com Python 1 12-14-2006 05:16 PM
how do i run another script from my python script nephish@xit.net Python 5 10-28-2005 02:06 AM



Advertisments