在apache上运行python脚本(Linux和Windows) [英] run python scripts on apache (linux and windows)

查看:100
本文介绍了在apache上运行python脚本(Linux和Windows)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need help with how to run scripts test.cgi for example in apache ? I created test script:

#!/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

这给了我错误.

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

Python is installed properly. Test.cgi chmod is 755

我是Linux新手.在窗口上,它也给我错误.在Windows上,它会给我:

I am new to linux. On wndows it gives me error too . On windows it gives me:

End of script output before headers: python_test.cgi

我在Windows上使用此脚本:

I use this script on windows:

#!"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!"

有什么主意吗?

推荐答案

将它们添加到您的配置文件中:

Add these to your configuration file:

  <Directory "/opt/lampp/htdocs/xampp/python">
      Options +ExecCGI
      AddHandler cgi-script .cgi .py
      Order allow,deny
      Allow from all
  </Directory>

并将您的代码替换为:

import cgitb
cgitb.enable()

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

print ("Hello World!")

对我有用.在Python 3.x中, print 是一个函数,因此您必须传递要打印的字符串作为争论.

It worked for me. In Python 3.x print is a function, so you have to pass the string to be printed as an arguement.

这篇关于在apache上运行python脚本(Linux和Windows)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆