[Tutor] Python isn't working with Apache (Windows)

Peter Otten __peter__ at web.de
Tue Aug 1 03:06:55 EDT 2017


Christopher McGrath wrote:

> I am trying to run a simple python web script in a browser with apache. I
> have apache installed and running perfectly. I installed Ruby and Perl

> I had Python 3.6 installed before and tried to test with these

> I also tried with #!Q:\LifeForce\Python36-32\python.exe. This one works
> worked from Window Command, but didn’t work from web browser like PERL and
> RUBY. 

> I am trying to run directly from Apache htdoc dir. Not from cgi dir. I
> think something is wrong with the shebang line. This is the error output
> in the web browser: Internal Server Error
> The server encountered an internal error or misconfiguration and was
> unable to complete your request. Please contact the server administrator
> at postmaster at localhost to inform them of the time this error occurred,
> and the actions you performed just before this error. More information
> about this error may be available in the server error log. Additionally, a
> 500 Internal Server Error error was encountered while trying to use an
> ErrorDocument to handle the request. This is what is shown in Apache’s
> error log:
> [Mon Jul 31 01:06:54.266478 2017] [cgi:error] [pid 5156:tid 1688] [client
> [98.5.128.152:51723] malformed header from script 'test.py': Bad header:
> [Mon Jul 31 01:06:54.270479 2017] [authz_core:error] [pid 5156:tid 1688]
> [[client 98.5.128.152:51723] AH01630: client denied by server
> [configuration: C:/Apache24

It looks like Apache is already running your script. It just can't make 
sense of its output. The header has to be separated from the data by an 
empty line. In your script that line contains an extra space that you must 
remove.

> I also tried with #!Q:\LifeForce\Python36-32\python.exe. This one works
> worked from Window Command, but didn’t work from web browser like PERL and
> RUBY. 

> Nothing worked. I don’t have any idea anymore. Please help!
> This is the simple code:

#!Q:\LifeForce\Python36-32\python.exe
> print ("Content-type: text/html")
  print ("")
> print ("<html><head>")
> print ("")
> print ("</head><body>")
> print ("Hello Python.")
> print ("</body></html>")

Does it work after this small change?



More information about the Tutor mailing list