简体   繁体   中英

Can't run Python scripts on an Apache web server (Windows 7)

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM