繁体   English   中英

Apache2 + Python

[英]Apache2 + Python

我试图在我的Apache2 Web服务器上运行一个简单的Python脚本。 但是我得到以下错误。 请帮助我,我不明白。 谢谢。

文件:

print('Content-Type: text/html; charset=utf-8\n')
print()
print("Hello, World!")

浏览器错误

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at webmaster@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

错误日志

[Fri May 13 13:35:05.520836 2016] [cgi:error] [pid 12967] [client ::1:41077] AH01215: (8)Exec format error: exec of '/var/www/html/index.py' failed
[Fri May 13 13:35:05.522775 2016] [cgi:error] [pid 12967] [client ::1:41077] End of script output before headers: index.py

我可以在终端中通过python index.py轻松执行文件,它看起来像这样:

Content-Type: text/html; charset=utf-8

()
Hello, World!

似乎我正在使用python 2.7。 (python -v)。 “请注意,标题后必须有一个空行('\\ n')”,这是什么意思? 您能给我一个代码示例吗?

在python 2.7中, print本身是一个函数,不需要使用print() ,将代码更改为:

print "Content-Type: text/html; charset=utf-8\n"
print ""
print "Hello, World!"

这应该工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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