使python脚本在IIS 8上运行

时间:2015-06-22 15:30:44

标签: python iis cgi

我将此添加到IIS上的处理程序模块中,用于我的网站

Request Path: *.py
Executable: "C:\Program Files\Python 3.5\python.exe"
Name: Python

我将IIS用户的权限授予此路径C:\ Program Files \ Python 3.5 \

然后我创建了这个test.py文件来测试我的配置

print("Content-Type: text/html")
print("")
print("""\
<html>
<body>
<h2>Hello World!</h2>
</body>
</html>
""")

但是当我尝试通过http://localhost/test.py

加载时,我收到了此错误网关错误
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:""

我缺少什么想法?

1 个答案:

答案 0 :(得分:1)

Microsoft's manual所示(链接中有更详细的描述):

  • 确保包含Python脚本的网站已设置应用程序
  • 验证.py文件的应用程序映射是否已设置
  • 验证是否在计算机的访问控制列表(ACL)中正确设置了文件和目录权限。

测试响应(python 2,转换应该很容易):

print
print 'Status: 200 OK'
print 'Content-type: text/html'
print

print '<HTML><HEAD><TITLE>Python Sample CGI</TITLE></HEAD>'
print '<BODY>'
print '<H1>This is a header</H1>'

print '<p>' #this is a comment
print 'See this is just like most other HTML'
print '<br>'
print '</BODY>'

似乎为您添加了Content-Length标题,您应该添加Status标题。