Question

I want to run python scripts on the mongoose web server. It worked fine with php-cgi.exe but not with python.exe.

Test script test.py:

print("Content-Type: text/html")
print("")
print("<h1>Hello World!</h1>")

Mongoose configuration mongoose.conf:

m .py=text/html
c py
I C:\\python\\python.exe

I've tried the script from the command prompt and it correctly returns:

Content-Type: text/html

<h1>Hello World!</h1>

Calling up http://localhost/test.py returns the following:

print("Content-Type: text/html")
print("")
print("<h1>Hello World!</h1>")

So the python code is not being interpreted and no errors are logged.

Was it helpful?

Solution 4

Solved: the mongoose.conf file is case sensitive. The following line is incorrect:

c py

it should be

C py

I can also confirm it works without #!python.exe or #!c:\python33\python.exe. How? Maybe mongoose is hard-wired to run python.exe when it sees a .py file and python.exe is in my PATH.

OTHER TIPS

A simple mongoose.conf:

document_root d:\root
listening_ports 80
cgi_extensions .py

hello.py:

#!python.exe
print("Content-Type: text/html")
print("")
print("<h1>Hello World!</h1>")

Works fine on my win-machine with PYTHONPATH set.

P.S. Instead of the #!python.exe I could use something like #!d:\python\python.exe or #!d:/python/python.exe - it works either way.

Update for mongoose 4.1, the config needs to be

cgi_pattern **.py$
cgi_interpreter C:\Python27\python.exe

Using mongoose-3.0, edit the mongoose configuration file mongoose.conf to include the lines

cgi_extensions .py
cgi_interpreter c:\python26\python.exe

and the python should execute and the html result should be displayed OK in the browser.

Running under windows 7, the OP's python code was placed in the file test.py and the url browsed was http://localhost:82/test.py based on my invoking mongoose with mongoose-3.0.exe -p 82 -e error_mongoose.txt.

Note that I did not need to have anything like #!c:\\python26\\python.exe in the first line of the python file. There may be other ways of getting python invoked, but I didn't have much luck getting it to work by specifying the interpreter exe as a #! comment on the first line of the script. I guess my solution is the next best thing - at least it works.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top