IIS 6.1中使用Python / CGI的“错误文件描述符”错误

背景

我试图(强调“尝试”)通过IIS(6.1,Windows Server 2008 R1)设置一个应用程序,通过一个Python脚本路由所有请求。 最终目标是在服务器上创build一个非常轻量级的API。

基本上,我采取了以下步骤:

  1. 添加到Windows的CGIfunction
  2. 默认网站下创build一个新的应用程序
  3. 添加一个处理程序映射,接受*并运行c:\Python27\python.exe -u "c:\inetpub\wwwroot\testapi\cgiadapter.py"
  4. 将应用程序的虚拟目录设置为testapi
  5. 将应用程序的物理path设置为c:\inetpub\wwwroot\testapi

做一个基本的testing,下面的脚本被testing和工作:

 import cgi, cgitb # Detailed error logging to screen cgitb.enable() # Output basic response print 'content-type:text/plain' print print 'Hello World' 

然后,我尝试更新脚本以读取来自stdin的请求

 import cgi, cgitb # Detailed error logging to screen cgitb.enable() # Attempt to read the raw request from CGI import sys request = sys.stdin.read() # Output basic response print 'content-type:text/plain' print print 'Hello World' 

突然,我收到以下错误: <type 'exceptions.IOError'>: [Errno 9] Bad file descriptor stdin.read() <type 'exceptions.IOError'>: [Errno 9] Bad file descriptor包含stdin.read()的行上的<type 'exceptions.IOError'>: [Errno 9] Bad file descriptor

问题

为什么stdin被认为是一个糟糕的文件?

我有没有在IIS中configuration错误,或者这是IIS的限制? 或者,也许是请求是通过标准input提供了一个不正确的假设?

谢谢!

我有同样的问题,并发现在IIS下,您需要使用CONTENT_LENGTH环境variables来限制从标准input读取的数据量。 以下是我添加到我的代码,以使其在IIS7上工作:

 try: import os request = sys.stdin.read(int(os.environ['CONTENT_LENGTH'])) except: request = '' 

有点晚…但我认为stdin (fd 0)已closures。