1

Here's the Python script itself (test.py):

#!/Users/misha/AppData/Local/Programs/Python/Python35-32
print("Content-Type: text/html\n")
print("\n\n")
print("<h1>Test</h1>")

I have this in my Apache's configuration file httpd.conf:

<Directory "c:/Apache24/htdocs">
    ...
    ...
    Options Indexes FollowSymLinks ExecCGI
    ...
    ...
</Directory>

AddHandler cgi-script .cgi .py

I restart Apache--everything else works just fine, but when I try to point to my Python test file in my browser, the server throws an Internal Server Error at me.

Here's my Apache's latest log file entries (I have edited them a little bit just for readability's sake):

(localhost-error.log)
[Thu Feb 11 14:24:39.357362 2016] [cgi:error] [pid 16872:tid 1028]
(OS 5)Access is denied.  : [client 127.0.0.1:54957] AH01223:
couldn't spawn child process: C:/Apache24/htdocs/test.py

(localhost-access.log)
127.0.0.1 - - [11/Feb/2016:14:24:39 -0800] "GET /test.py HTTP/1.1"
500 528

I don't even know what to do now.

2 Answers 2

2

It may be that Apache can't find the python interpreter. You should make sure the shebang in your file is correct. Test if you can run the file from a different folder.

Sign up to request clarification or add additional context in comments.

1 Comment

The shebang line was the problem. Changed it to: #!/Users/misha/AppData/Local/Programs/Python/Python35-32/python.exe (I just added "python.exe" on the end) Now it works.
0

Make sure you put shebang line in your code.

And check your script permissions. It should be executable.

To change file permission to executable in Linux: chmod +x filename.py

I don't know about windows.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.