[Tutor] Re: Help with 500 error on cgi script

Sheila King sheila@thinkspot.net
Sun, 18 Mar 2001 16:42:30 -0800


On Sun, 18 Mar 2001 18:46:07 -0500, D-Man <dsh8290@rit.edu>  wrote about Re:
[Tutor] Re: Help with 500 error on cgi script:

:On Sun, Mar 18, 2001 at 12:11:07PM -0800, Sheila King wrote:
...<snippage>...
:I think you are seeing an issue with regards to Unix systems and
:users and locating specific versions of things.
:
:| I went to the directory where I have Python-2.0 installed, and
:| invoked the interpreter, and at the prompt typed:
:| 
:| >>>import cgi
:| >>>cgi.test()
:| 
:| and it rattled off its test script. 
:
:This shows that the installation works _with the environment created by
:your login scripts_.
...<snippage>...
:Your script is being invoked by the web server (apache, whatever).  I
:think that apache runs as "http" or maybe "nobody".  Scripts will be
:run as that user, or possibly a special user with restricted access to
:the system (probably named "cgi" or some such). 

No, our Apache server is using suexec and runs cgi scripts under our own
userID.

: Is your python
:installation world readable and executable? 

Yes. Well, 755. That is world readable and executable, right?

: Also, what is the first
:line of the script?  If it is 
:
:#!/usr/bin/env python
:
:as I think I saw, 

No, the first line of the script is
#!/big/dom/xthinkspot/Python-2.0/python -v

:you are using whatever 'python' executable is found
:in the path.  Probably 1.5.2 that is installed on the system.  Change
:the first line of the script to
:
:#!/big/dom/xthinkspot/Python-2.0/python

Already done.

:to specifically direct execution to your python interpreter.  Again,
:I'm not sure this will work.  The #! thing is usually interpreted by
:the shell to mean "run this binary (interpreter) on this file".  If
:the web server executes interpreters automatically then it will
:probably ignore this line.  If it executes it in a shell it should
:work.  

It must be using that line, because when I don't have it set correctly, the
script won't even begin to run at all.


:If all else fails, write a simple C/C++ program that simply execs the
:proper interpreter on the script giving it the necessary environment.

Thanks. I may look into that tonight, if I'm still getting nowhere on this
problem.

:To determine if I am at all close in diagnosing the problem, make a
:simple script that is nothing more than :
:
:#!/usr/bin/env python
:
:import sys
:
:print "Content-type text/html\n"
:print sys.version
:
:
:to show what python version is being used by the web server/CGI
:script.

Interesting idea. I may try that tonight, as well.

:You can also add "-v" to the end of the first line of the script to
:get more information in the syslog.

I have already done that. Here is a portion of the log file that resulted when
I tried that (it is much too long to post the whole thing):

%% [Sun Mar 18 15:51:24 2001] POST /cgi-bin/listsettings.py HTTP/1.0
%% 500 /big/dom/xthinkspot/cgi-bin/listsettings.py
%request
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*
Accept-Charset: iso-8859-1,*,utf-8
Accept-Encoding: gzip
Accept-Language: en,de-DE,fr,ru,ko,zh,zh-CN,zh-TW,cs
Connection: Keep-Alive
Content-length: 67
Content-type: application/x-www-form-urlencoded
Host: www.thinkspot.net
Referer: http://www.thinkspot.net/sheila/computers/listManagementtest.html
User-Agent: Mozilla/4.61 [en] (Win98; U)

subscriberEmail=&command=%3CSelect+an+Item%3E&Submit=Submit+Changes
%response
%stderr
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
'import site' failed; traceback:
ImportError: No module named site
Python 2.0 (#1, Jan 15 2001, 01:09:04) 
[GCC 2.7.2.3] on linux2
Type "copyright", "credits" or "license" for more information.
Traceback (most recent call last):
  File "listsettings.py", line 5, in ?
    import cgi
ImportError: No module named cgi
# clear __builtin__._
# clear sys.path
# clear sys.argv
# clear sys.ps1
# clear sys.ps2
# clear sys.exitfunc
# clear sys.exc_type
# clear sys.exc_value
...<rest snipped>...

I think that you can see here, that it is calling my private install of
Python-2.0.  Why it can't find my modules is a mystery to me. It finds them
just fine when I run the script from the command line.

Heh...I was thinking of letting my computer science students do some cgi
scripting the last two weeks of class (end of May) as an optional project. (In
C++, though, not Python...) I may rethink that...? Well, we would be working
on Windows machines on a web server running on our desktop, though.

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/

P.S. I've posted the full script here, for anyone who is interested:
http://www.thinkspot.net/test/listsettings.py
<tee-hee...this was supposed to be a one to two hour little project that I was
going to knock off to make my life as a mailing list owner a little easier.
*snort!*>