Click here to Skip to main content
15,891,633 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi, I am researching on Python language, its syntax and other features are as easy as others' but I want to use it as a server-side scripting language like PHP with Apache Web Server (AppServ) but it seems to very difficult, I think I have to change some info in configuration file but what to change are not easy to find out for me. My want is very simple, for example, I have the following HelloWorld python file:
#!E:/Python32/python.exe
print("Hello World!")


and I save it as "HelloPython.py" and save it in "E:/AppServ/www/cgi-bin/"
and I want when users type "http://localhost/cgi-bin/HelloPython.py" in the Address bar of a browser, hit enter and it should display the "Hello World!".

I have searched a little with Google and tried some things like:
Options +ExecCGI
AddHandler cgi-script .py .pl

And it seemed that the changes to the configuration file took effect when the server threw back a message like "Internal Server Error" and I opened the Server error log file to see exactly what happened and it said "malformed header from script. Bad header=Hello World!: HelloPython.py". Well, malformed header??? I saved my python file using ANSI option from the save file dialog of NotePad, what's wrong with that?

Could your please help me out this complexity? I can feel it's not easy at all.
Your help would be highly appreciated anyway, thanks!
Posted
Updated 31-Aug-12 8:35am
v3

 
Share this answer
 
Comments
supernorb 31-Aug-12 14:58pm    
I think you guided me to choose another solution than give a direct solution for my problem. My example is very simple which is needed to work as it should do, however I will try your solution after I solve this. Thank you!
Check out the documentation for Python's CGI library[^]

Basically, you're missing an HTTP header, and there's a sample in the documentation with a simple header.
 
Share this answer
 
Comments
supernorb 31-Aug-12 15:08pm    
Yeah, you gave me a great link to solve my problem, and you possibly knew what's wrong in my HelloPython.py, I thought it was the same to PHP.
This is a so-called direct solution, Thank you very much!
XML
Check out mod_python

http://www.modpython.org/
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900