Click here to Skip to main content
12,948,566 members (62,635 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:
#!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 31-Aug-12 5:47am
supernorb2.7K
Updated 31-Aug-12 8:35am
v3
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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

Solution 4

Check out mod_python
 
http://www.modpython.org/
  Permalink  

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 5,419
CHill60 3,275
Maciej Los 2,778
Jochen Arndt 1,935
ppolymorphe 1,795


Advertise | Privacy | Mobile
Web02 | 2.8.170524.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