python - End of script output before headers error with Python Script
问题描述
I've read multiple SO posts regarding this, but can't seem to get this to work. This is my first time working with Python on Apache so I would appreciate the help I can get!
So ultimately, I'm trying to run a Python script in my htdocs, but I can't seem to just get the simple python script running on XAMPP. I keep getting a 500 error:
myurl.py
#!/usr/bin/env python3
print("Content-Type: text/html")
print()
print ("""
<TITLE>CGI script ! Python</TITLE>
<H1>This is my first CGI script</H1>
Hello, world!
"""
)
解决方案
根据讨论,这里有多个问题,通过检查error.log
apache编写的然后进行适当的更改来解决。
第一个错误是:
[2018 年 11 月 20 日星期二 17:49:06.593901] [cgi:error] [pid 47854] [client ::1:50462] AH01215: (13)Permission denied: exec of '/Applications/XAMPP/xamppfiles/htdocs/myurl. py'失败:/Applications/XAMPP/xamppfiles/htdocs/myurl.py [Tue Nov 20 17:49:06.595547 2018] [cgi:error] [pid 47854] [client ::1:50462] 头文件前的脚本输出结束: myurl.py
这里的相关部分是:
(13)Permission denied: exec of '/Applications/XAMPP/xamppfiles/htdocs/myurl.py' failed
需要对.py
正在执行的文件设置权限,以允许运行 apache 进程的用户执行脚本。这是使用chmod
.
然后,又出现了一个错误:
[2018 年 11 月 20 日星期二 17:59:04.720816] [cgi:error] [pid 48715] [client ::1:50555] AH01215:python3:没有这样的文件或目录:/Applications/XAMPP/xamppfiles/htdocs/myurl.py [2018 年 11 月 20 日星期二 17:59:04.720884] [cgi:error] [pid 48715] [client ::1:50555] 标头之前的脚本输出结束:myurl.py
相关部分是:
python3: No such file or directory
这表明系统找不到python3
要执行的二进制文件。解释器的正确路径python3
必须使用which python3
. 然后将其编辑到脚本的 shebang 行中。
推荐阅读
- c++ - 构造函数类需要参数但想将其用作属性
- delphi - 错误:没有选择访问查看权限
- r - 计算变化是否大于 0.25
- python - python中的corner_harris使用JAFFE数据集
- scala - 无法读取管道分隔的 csv
- java - Jpackage 不能与 JDBC 依赖完美配合
- vue.js - Vue + Axios:向第三方网站发出 GET 请求会引发 CORS 错误
- r - 如何在某个时间戳之前删除数据框中的所有行?
- python - 为什么 python 中的 geometry('value') 方法需要字符串值?
- git - 为什么我在浅克隆后看不到 git 存储库的远程分支?