Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';t在Apache web服务器(Windows 7)上运行Python脚本_Python_Apache - Fatal编程技术网

Can';t在Apache web服务器(Windows 7)上运行Python脚本

Can';t在Apache web服务器(Windows 7)上运行Python脚本,python,apache,Python,Apache,下面是Python脚本本身(test.py): 我甚至不知道现在该怎么办。可能是Apache找不到python解释器。你应该确保文件中的shebang是正确的。测试您是否可以从其他文件夹运行该文件。确保在代码中插入shebang行 并检查您的脚本权限。它应该是可执行的 在Linux中将文件权限更改为可执行文件:chmod+x filename.py 我不知道windows的情况。问题出在shebang生产线上。将其更改为:#/Users/misha/AppData/Local/Programs/

下面是Python脚本本身(test.py):


我甚至不知道现在该怎么办。

可能是Apache找不到python解释器。你应该确保文件中的shebang是正确的。测试您是否可以从其他文件夹运行该文件。

确保在代码中插入shebang行

并检查您的脚本权限。它应该是可执行的

在Linux中将文件权限更改为可执行文件:chmod+x filename.py


我不知道windows的情况。

问题出在shebang生产线上。将其更改为:#/Users/misha/AppData/Local/Programs/Python/Python35-32/Python.exe(我刚刚在末尾添加了“Python.exe”)现在可以工作了。
#!/Users/misha/AppData/Local/Programs/Python/Python35-32
print("Content-Type: text/html\n")
print("\n\n")
print("<h1>Test</h1>")
<Directory "c:/Apache24/htdocs">
    ...
    ...
    Options Indexes FollowSymLinks ExecCGI
    ...
    ...
</Directory>

AddHandler cgi-script .cgi .py
(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