Mailing List Archive

stupid Win-CGI getting started question
Installed the basic Python stuff. I can run the interpreter. But not clear on
getting it configured properly to talk CGI with my WinNT Netscape Enterprise
server. I set a CGI folder path properly, but I get a nasty error message.
But it's not a file-not-found, so I know it's finding the .py file. So I'm
guessing it's not finding the executable.

How should that first #! be changed for Windows users? Could that be it?

Could the fact that all my Python stuff is under
d:\program files\python\
be part of the problem (the long folder name with a space in it)?

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
stupid Win-CGI getting started question [ In reply to ]
seitz@mail.medscape.com wrote in <7f0f0h$pfb$1@nnrp1.dejanews.com>:

>Installed the basic Python stuff. I can run the interpreter. But not clear on
>getting it configured properly to talk CGI with my WinNT Netscape Enterprise
>server. I set a CGI folder path properly, but I get a nasty error message.
>But it's not a file-not-found, so I know it's finding the .py file. So I'm
>guessing it's not finding the executable.
>
>How should that first #! be changed for Windows users? Could that be it?
>
>Could the fact that all my Python stuff is under
>d:\program files\python\
>be part of the problem (the long folder name with a space in it)?

I tried all sorts of configuration changes to get it to run .py files directly,
and eventually gave it up as a bad job (mostly because I didn't want to risk
breaking the server).

The way I get CGI scripts to run with Netscape Enterprise server on NT is to
put them in .cmd files instead of .py files. For example:

---------test.cmd----------------
@c:\Progra~1\Python\python -x "%~f0" %* & goto :EOF
import os

print "Content-type: text/html"
print
print "<HTML><HEAD><TITLE>Test</TITLE></HEAD>"
print "<body>Hello world from python.<p>"

for k in os.environ.keys():
print k, os.environ[k], "<br>"
print "</body>"
---------end of test.cmd---------
You would need to change the path to reflect the location of your copy of
Python, either use the 8.3 filename as above, or put the filename in quotes:
@"c:\Program Files\Python\python" -x "%~f0" %* & goto :EOF
works.

To get Bobo (now ZPublisher) working, I use a wrapper .cmd file like this:
--------------form.cmd----------------
@c:\Progra~1\Python\pythonw -x "%~f0" %* & goto :EOF
import traceback, sys
try:
sys.path[0:0] = ["h:\\staff\\tvoc\\python"]

import cgi_module_publisher
cgi_module_publisher.publish_module("form")

except:
print 'Content-type: text/plain\n\n'
print 'An error occured in attempting to set up the environment for
this application.'
-------------end of form.cmd-------------------

sys.path needs to be set to include the directory with the python code you want
to publish, but the python code need not be visible to the web users.

I then set up a redirect in the Netscape server configuration so that an
ordinary URL with an html extension gets redirected to form.cmd and the end
user doesn't even need to know that any CGI is involved.

--
Duncan Booth duncan@dales.rmplc.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
http://dales.rmplc.co.uk/Duncan
stupid Win-CGI getting started question [ In reply to ]
In article <8DA86302Bduncanrcpcouk@news.rmplc.co.uk>,
Duncan Booth <duncan@rcp.co.uk> wrote:
> seitz@mail.medscape.com wrote in <7f0f0h$pfb$1@nnrp1.dejanews.com>:
>
> >...But not clear on
> >getting it configured properly to talk CGI with my WinNT Netscape Enterprise
> >server.
> >
> >How should that first #! be changed for Windows users? Could that be it?
> >
> >Could the fact that all my Python stuff is under
> >d:\program files\python\
> >be part of the problem (the long folder name with a space in it)?
>
> I tried all sorts of configuration changes to get it to run .py files
directly,
> and eventually gave it up as a bad job (mostly because I didn't want to risk
> breaking the server).
>
> The way I get CGI scripts to run with Netscape Enterprise server on NT is to
> put them in .cmd files instead of .py files. For example:
>
> ---------test.cmd----------------
> @c:\Progra~1\Python\python -x "%~f0" %* & goto :EOF
> import os
>
> print "Content-type: text/html"
> print
> print "<HTML><HEAD><TITLE>Test</TITLE></HEAD>"
> print "<body>Hello world from python.<p>"
>
> for k in os.environ.keys():
> print k, os.environ[k], "<br>"
> print "</body>"
> ---------end of test.cmd---------
> You would need to change the path to reflect the location of your copy of
> Python, either use the 8.3 filename as above, or put the filename in quotes:
> @"c:\Program Files\Python\python" -x "%~f0" %* & goto :EOF
> works.

I tried your test.cmd (after changing the first line, using your quoted path
and making it my path of course). Now I get a response back of internal or
external command, operable program or batch file. The server acts shows this
as a successful delivery (no error in the logs, status=200). Does that mean
the problem is now within Python?

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
stupid Win-CGI getting started question [ In reply to ]
In article <8DA86302Bduncanrcpcouk@news.rmplc.co.uk>,
Duncan Booth <duncan@rcp.co.uk> wrote:
> seitz@mail.medscape.com wrote in <7f0f0h$pfb$1@nnrp1.dejanews.com>:
>
> >Installed the basic Python stuff. I can run the interpreter. But not clear on
> >getting it configured properly to talk CGI with my WinNT Netscape Enterprise
> >server. I set a CGI folder path properly, but I get a nasty error message.
> >But it's not a file-not-found, so I know it's finding the .py file. So I'm
> >guessing it's not finding the executable.

> I tried all sorts of configuration changes to get it to run .py files
directly,
> and eventually gave it up as a bad job (mostly because I didn't want to risk
> breaking the server).
>
> The way I get CGI scripts to run with Netscape Enterprise server on NT is to
> put them in .cmd files instead of .py files.

So nobody can run .py files as CGI?

Is this a known problem? What's its scope? Only Netscape/NT? What about IIS?
What about Netscape/Solaris?

I'm trying to keep my code generic enough that it can be moved to other
platforms/servers down the road (which is why I haven't been looking at nsapy
or Medusa or ZopeHTTP...), so I don't want to work around a problem now and
just have it hit me again later. I'd like to understand the nature of the
problem enough to evaluate alternative solutions.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
stupid Win-CGI getting started question [ In reply to ]
bill_seitz@my-dejanews.com wrote in <7f2db8$dev$1@nnrp1.dejanews.com>:
>I tried your test.cmd (after changing the first line, using your quoted path
>and making it my path of course). Now I get a response back of internal or
>external command, operable program or batch file. The server acts shows this
>as a successful delivery (no error in the logs, status=200). Does that mean
>the problem is now within Python?

Looks like you are getting the second line of the message:
The name specified is not recognized as an
internal or external command, operable program or batch file.

It sounds like you still don't have the right path to python, or it is
protected so you can't access it. I would check the file permissions: you
probably need to give SYSTEM (or whatever user the CGI process is running as)
on the web server full access to the python directory.

Try creating a CGI cmd file like this:
----access.cmd---------
@echo Content-type: text/plain
@echo ""
@echo on
dir d:\
dir "d:\program files"
dir "d:\program files\python"
----end of access.cmd---------
That should show you the python directory, if not, you need to change the
permissions.

--
Duncan Booth duncan@dales.rmplc.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
http://dales.rmplc.co.uk/Duncan
stupid Win-CGI getting started question [ In reply to ]
bill_seitz@my-dejanews.com wrote in <7f2no0$n80$1@nnrp1.dejanews.com>:

>> The way I get CGI scripts to run with Netscape Enterprise server on NT
is to
>> put them in .cmd files instead of .py files.
>
>So nobody can run .py files as CGI?
>
>Is this a known problem? What's its scope? Only Netscape/NT? What about
IIS?
>What about Netscape/Solaris?
>
I didn't say it was impossible to run .py files as CGI, simply that I had
problems getting it to work. Since my number one priority was not to take
the web server off-line at all, there were limits to how far I could play
around with it. I'm sure there must be some way to get it to work, but I
got enough for my purposes.

--
Duncan Booth duncan@dales.rmplc.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
http://dales.rmplc.co.uk/Duncan
stupid Win-CGI getting started question [ In reply to ]
In article <8DA96361Fduncanrcpcouk@news.rmplc.co.uk>,
Duncan Booth <duncan@rcp.co.uk> wrote:
> It sounds like you still don't have the right path to python, or it is
> protected so you can't access it. I would check the file permissions: you
> probably need to give SYSTEM (or whatever user the CGI process is running as)
> on the web server full access to the python directory.
>
> Try creating a CGI cmd file like this:
> ----access.cmd---------

Ugh, pardon my sloppiness. Your access.cmd worked fine. Then I went back to
the previous file, took off the stuff on your first line after the Python
path, and got the same error message followed by the rest of the contents of
the file. So that told me that the path was the offending line. I looked more
carefully, and realized (d'oh) that the path was not just a folder path to
your code files, or the path to the Python executable, but the actual path
including the executable filename itself. Once I adjusted my first line to
match that, it started working fine. Now, if only I could get .py files to
work...

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
stupid Win-CGI getting started question [ In reply to ]
In article <8DA9637FEduncanrcpcouk@news.rmplc.co.uk>,
Duncan Booth <duncan@rcp.co.uk> wrote:

> I didn't say it was impossible to run .py files as CGI, simply that I had
> problems getting it to work. Since my number one priority was not to take
> the web server off-line at all, there were limits to how far I could play
> around with it. I'm sure there must be some way to get it to work, but I
> got enough for my purposes.

Gotcha.

I did some more playing around. No success, but here's what I did/found: When
I try to call a .py file I get the "This server has encountered an internal
error which prevents it from fulfilling your request" message. The NES error
log shows: [15/Apr/1999:10:35:53] failure: for host 192.246.193.43 trying to
GET /pcgi/dntest.py, send-cgi reports: could not send new process (File Not
Found Error) [15/Apr/1999:10:35:53] failure: cgi_send:cgi_start_exec
d:\program files\python\lib\dntest.py failed

If I rename the .py file to .cmd and call it with that name, it works fine.

I'm defining a /pcgi/ path to point to the location of the python files, so
I'm not counting on the suffix to mean anything. All the various CGI folders
get mapped to object name="cgi", but again, since suffix is irrelevant, that
shouldn't be the problem.

I went into mime.types and added the py extension to the cgi reference (note
that cmd is not in that extension list). Still get an error, but the log
changes to [15/Apr/1999:10:52:57] failure: for host 192.246.193.43 trying to
GET /pcgi/dntest.py, send-cgi reports: could not send new process (Error
Number is unknown) [15/Apr/1999:10:52:57] failure: cgi_send:cgi_start_exec
d:\program files\python\lib\dntest.py failed

Does this suggest any clues? I've asked a friend who doesn't know Python but
knows Netscape pretty well. Will report back if he has any suggestions.


-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
stupid Win-CGI getting started question [ In reply to ]
I gave up, installed Apache, and got it (and the .py CGI) running in 10
minutes.


-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
stupid Win-CGI getting started question [ In reply to ]
On 14 April 1999 19:45, bill_seitz@my-dejanews.com
[SMTP:bill_seitz@my-dejanews.com] wrote:
> So nobody can run .py files as CGI?
>
> Is this a known problem? What's its scope? Only Netscape/NT? What about IIS?

It was certainly possible to run .py files as CGI under IIS 2. I did not need
to upgrade that system, so cannot be sure about later versions of IIS, but
would find it extremely hard to believe that anyone would remove the ability to
use an abitrary external program to provide a CGI resource to a web server from
a mainstream web server.

I do remember seeing a (at least one, maybe more) posting about differences in
configuring IIS2/3/4 w.r.t. external programs (e.g. stuff which worked fine
under IIS2/3 stopped working when the server was upgraded to version 4).

The problem has to be along these lines. The CGI spec (I understand) simply
requires programs/languages that can handle standard input (stdin) and produce
standard output (stdout).

> I'm trying to keep my code generic enough that it can be moved to other
> platforms/servers down the road (which is why I haven't been looking at nsapy
> or Medusa or ZopeHTTP...), so I don't want to work around a problem now and
> just have it hit me again later. I'd like to understand the nature of the
> problem enough to evaluate alternative solutions.

I have done some work with ISAPI (the Microsoft equivalent to NSAPY). There
are performance gains with these approaches, but you definitely lock yourself
into a single web server supplier (unless someone has come up with a neat way
of producing cross-platform support for these plug-ins). CGI has the big
advantage that it is supported by all non-toy web servers, and the actual code
should not need changing between different web servers.

Richard