When try to execute a cgi script, get the error: “

2019-07-15 11:41发布

问题:

When I try to execute a cgi script (via a localhost), I get the following error

OSError: [WinError 193] %1 is not a valid Win32 application

Any ideas why ??

Completely lost...

.


Additional Information:

The localhost is generated by the following

python -m http.server --cgi 8000

The cgi script is called by an ajax 'get' request (simplified)

ajax({
   type: "GET", 
   url: "cgi-bin/myScript.cgi",
   onSuccess: function(html){
       //do stuff
   }
});

I have tested to check whether it's the contents of the cgi script causing this and I am convinced it's not the problem. For instance, if I try to execute an empty 'myScript.cgi' in the manner above, I still get the error.

Also, the cgi script (written in python) works fine when run through the command line.

回答1:

So turns out it was a server config error....

I came across this tutorial,

http://anh.cs.luc.edu/python/hands-on/3.1/handsonHtml/dynamic.html

which references a localCGIServer.py script available here,

http://anh.cs.luc.edu/python/hands-on/examples/www/localCGIServer.py

And the server script gets the job done

*

For Python 3 change this line

cgiServer = BaseHTTPServer.HTTPServer(server_addr, CGIExtHTTPRequestHandler)

to

cgiServer = http.server.HTTPServer(server_addr, CGIExtHTTPRequestHandler)