El servidor local Py2Exe no ejecuta CGI

I have a certain Python program that relies on a CGI script, which works when I launch a Python BaseHTTPServer with a CGIHTTPServer. But I would like all this to be run without installing Python, so I used Py2Exe.

I manage to create a .exe from my script, which indeed creates a working local web server when executed. CGI scripts, however, are just shown as code and not executed.

Here's the whole server script, which also launches the default browser:

#!/usr/bin/env python

import webbrowser
import BaseHTTPServer
import CGIHTTPServer

server = BaseHTTPServer.HTTPServer
handler = CGIHTTPServer.CGIHTTPRequestHandler
server_address = ("", 8008)
handler.cgi_directories = ["/cgi"]
httpd = server(server_address, handler)

However, that script.py is just shown and not executed. I can't figure out why, and I have tried a few different versions in handler.cgi_directories, just in case...

preguntado el 28 de agosto de 12 a las 08:08

You are starting the browser before you start the server -

Hehe, no, that's not the answer, but thanks. That script works when called by Python - the browser takes a while to initialize, so httpd is already serving by then. If I start the browser after 'serving forever' that line is never called, though. Anyway, once the server is up and running, I may open a browser window manually and browse to that address, with the same results: I see the CGI code, it's not being executed. -

run tcpdump on the lo inerface and see the requests and responses. -

I guess I can do that with Firebug too, right? But I'm not sure what's your point. What am I looking for? CGI scripts are not executed - it's a server issue, right? Similar to .htaccess not being properly configured in Apache. I suspect, however, that it is related to how Python interprets CGI. Maybe it calls itself (Python), which wouldn't work within a .exe because... well, there's no Python to be found. -

I think its more likely a webroot path issue. If it were python you would get an error, not the file. -

1 Respuestas

problem is py2exe only converts your server script to exe, all cgi scripts are still .py and they require python installation to run. try converting each and every script in 'cgi' directorio.
Assuiming you have server.py in root dir and cgi scripts at wwwroot\cgi-bin su setup.py debería verse como

#!usr/bin/env python
from distutils.core import setup
import py2exe, os

                        "unbuffered": True,
                        "packages": "cgi, glob, re, json, cgitb",       # list all packages used by cgi scripts
                        "optimize": 2,
                        "bundle_files": 1
os.rename("dist\\library.zip","dist\\library.zip.bak")                  # create backup of the library file

for f in os.listdir("wwwroot\\cgi-bin"):                                # list all cgi files with relative path name

    console= files,
                        "dist_dir": "dist\\wwwroot\\cgi-bin",
                        "excludes": "cgi, glob, re, json, cgitb",       # we are going to discard this lib, may as well reduce work
                        "bundle_files": 1
    zipfile="..\\..\\library.zip")                                      # make sure zipfile points to same file in both cases

os.remove("dist\\library.zip")                                          # we don't need this generated library
os.rename("dist\\library.zip.bak","dist\\library.zip")                  # we have already included everything in first pass

contestado el 17 de mayo de 13 a las 09:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.