[Tutor] Using CGIHTTPServer on Windows to run Perl & Python scripts - POST to Perl fails

Python python at venix.com
Sun Nov 13 02:29:44 CET 2005


I should have included the REQUEST_METHOD before.  Yes it is correct.

This is a useful test perl script I downloaded from a Perl oriented
site:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#!/usr/bin/perl
use CGI;

$cgi = new CGI;

for $key ( $cgi->param() ) {
        $input{$key} = $cgi->param($key);
}

print qq{Content-type: text/html

<html><head></head><body>};

#print every key in the environment
foreach $key (sort (keys %ENV)) {
        print $key, ' = ', $ENV{$key}, "<br>\n";
}

for $key ( keys %input ) {
        print $key, ' = ', $input{$key}, "<br>\n";
}

#print a couple of simple forms: a POST form and a GET form
print qq{<form method="POST" ><input type="submit" value="Post Request">
                        <input name="postfield"></form>};
print qq{<form method="GET" ><input type="submit" value="Get  Request ">
                        <input name="getfield" ></form>};

print qq{</body></html>};
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

I think I am pushing the limits of being on topic here, though having
the Python CGI server work with Perl under Windows would be nice.

I suppose it is possibly an issue with my Perl setup in Windows.  It's
Perl 5.8.7 from ActiveState binary build 813.  The Windows version is
(from sys.getwindowsversion):
(5, 1, 2600, 2, 'Service Pack 2')

Here is the webserver code:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#! /usr/bin/env python
# cgiserver.py

import sets, posixpath, sys, os, urllib, select

from BaseHTTPServer import HTTPServer
from CGIHTTPServer import CGIHTTPRequestHandler
from SocketServer import ThreadingMixIn

class ThreadingServer(ThreadingMixIn, HTTPServer):
    pass

class MyRequestHandler(CGIHTTPRequestHandler):
    '''I could not figure out how to convince the Python os.stat module
    that the perl scripts are executable so that the server would actually
    run them.  The simple solution is to override is_executable to always
    return true.  (The perl scripts are indeed executable and do run.)
    '''
    def is_executable(self, path):
        return True


serveraddr = ('',8000)
srvr = ThreadingServer(serveraddr, MyRequestHandler)
srvr.serve_forever()
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

I assume anyone with access to a Windows computer could try this.  The
server expects to be in a directory with a subdirectory of
	cgi-bin
cgi-env.pl should be in the cgi-bin directory

The URL to use cgi-env.pl is
	http://localhost:8000/cgi-bin/cgi-env.pl

I'd be curious if this issue is peculiar to the version of Windows that
I am dealing with here.  I have no other Windows web server environment
to check against.

The CGIRequestHandler can't be doing anything terribly wrong, or the
Python scripts would fail.  I will see if I can use the cgi.pm source to
figure something out.


Python schrieb:
> The Python scripts are OK.  The Perl scripts do not receive the POST
> parameters so they execute as though no parameters were supplied.
I've
> added logic to display the environment and that appears (to my Python
> oriented eye) to be correct.  In particular, the CONTENT_LENGTH and
> CONTENT_TYPE are correct.  GET requests work correctly.

Could you post some code examples, i.e. the HTML form which does the
POST
request and the Perl code to handle it?

Have you checked, that the REQUEST_METHOD is really POST?


Chris


-- 
Lloyd Kvam
Venix Corp



More information about the Tutor mailing list