Click here to Skip to main content
12,951,983 members (58,345 online)
Rate this:
Please Sign up or sign in to 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:
print("Hello World!")

and I save it as "" and save it in "E:/AppServ/www/cgi-bin/"
and I want when users type "http://localhost/cgi-bin/" 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!:". 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 31-Aug-12 5:47am
Updated 31-Aug-12 8:35am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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!
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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.
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, I thought it was the same to PHP.
This is a so-called direct solution, Thank you very much!
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

Check out mod_python

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,239
CHill60 3,490
Maciej Los 3,083
Jochen Arndt 1,975
ppolymorphe 1,880

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 3 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100