I'm trying to run the following "Hello world" Python cgi script
#!/usr/bin/env python
print "Content-Type: text/plain;charset=utf-8"
print
print """\
<html>
<head>
<title>Python - Hello World</title>
</head>
<body>
Hello World
</body>
</html>
"""
and gets "Internal Server Error"
Apache error log shows the following error message
[cgi:error] [pid 10068:tid 1140] (9)Bad file descriptor: [client ::1:54696] AH01222: don't know how to spawn child process: C:/httpd-2.4.37-win64-VC15/Apache24/cgi-bin/hello.py
Am I missing something in .conf?
it looks like you are running Apache on windows because the error message say c:\httpd-2.4.37-win64-VC15
however your hashbang on the first line of the script is for linux/unix installation of Python
change
#!/usr/bin/env python
to
#! c:/your/windows/python/install_directory
cheers
Rijo
You have spaces in file path for python.exe in which case enclose it in doublequotes as below:
#!"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\python\Python 3.10\python.exe"
Thanks, for your quick response Rijo.!!
It was really stupid of me. changed the first line to #!C:\Python26\Python and it worked!!
It is showing this error
[Tue Jun 07 11:37:43.894071 2022] [cgi:error] [pid 3988:tid 1816] (OS 2)The system cannot find the file specified. : [client 127.0.0.1:57986] couldn't create child process: 720002: index.py
[Tue Jun 07 11:37:43.894071 2022] [cgi:error] [pid 3988:tid 1816] (OS 2)The system cannot find the file specified. : [client 127.0.0.1:57986] AH01223: couldn't spawn child process: D:/project/base/index.py
below is the code
#!C:\ProgramData\Microsoft\Windows\Start Menu\Programs\python\Python 3.10\python.exe
print("Content-Type: text/html")
print("Hello World")