首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在apache (linux和windows)上运行python脚本

在apache (linux和windows)上运行python脚本
EN

Stack Overflow用户
提问于 2014-12-19 10:38:47
回答 1查看 3.7K关注 0票数 0

我需要帮助如何运行脚本test.cgi,例如在apache中?我创建了测试脚本:

代码语言:javascript
复制
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

# enable debugging
import cgitb
cgitb.enable()

print "Content-Type: text/plain;charset=utf-8"
print

print "Hello World!

当我运行localhost/cgi-bin/test.cgi

这给我带来了错误。

代码语言:javascript
复制
Internal Server Error

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

Please contact the server administrator, webmaster@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.
Apache/2.2.22 (Ubuntu) Server at localhost Port 80

Python已正确安装。Test.cgi chmod为755

我是linux新手。它也会给我带来错误。在窗户上它给了我:

代码语言:javascript
复制
End of script output before headers: python_test.cgi

我在windows上使用这个脚本:

代码语言:javascript
复制
#!"C:\Python34\python.exe"
# -*- coding: UTF-8 -*-

# enable debugging
import cgitb
cgitb.enable()

print "Content-Type: text/plain;charset=utf-8"
print

print "Hello World!"

知道吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-19 11:40:19

将这些添加到您的配置文件中:

代码语言:javascript
复制
  <Directory "/opt/lampp/htdocs/xampp/python">
      Options +ExecCGI
      AddHandler cgi-script .cgi .py
      Order allow,deny
      Allow from all
  </Directory>

并将代码替换为:

代码语言:javascript
复制
import cgitb
cgitb.enable()

print ("Content-Type: text/plain;charset=utf-8")
print ()

print ("Hello World!")

对我起作用了。在Python3.x中,print是一个函数,因此必须传递字符串才能打印为一个论证。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27564253

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档