如何使用WFastCGI+;IIS+;Python 3.4?

如何使用WFastCGI+;IIS+;Python 3.4?,python,iis,Python,Iis,作为一名刚刚完成codeacademy免费课程的python新手,我遵循了上的说明,并成功地在IIS上安装了python处理程序 然后,我根据web.config创建了一个python文件(模块)my_app.py,其中包含以下代码(我从某处改编): 导航到本地主机站点时,IIS返回以下错误: Error occurred while reading WSGI handler: Traceback (most recent call last): File "C:\Python34\lib

作为一名刚刚完成codeacademy免费课程的python新手,我遵循了上的说明,并成功地在IIS上安装了python处理程序

然后,我根据
web.config
创建了一个python文件(模块)
my_app.py
,其中包含以下代码(我从某处改编):

导航到本地主机站点时,IIS返回以下错误:

Error occurred while reading WSGI handler:

Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\wfastcgi.py", line 779, in main
    env, handler = read_wsgi_handler(response.physical_path)
  File "C:\Python34\lib\site-packages\wfastcgi.py", line 621, in read_wsgi_handler
    handler = get_wsgi_handler(os.getenv('WSGI_HANDLER'))
  File "C:\Python34\lib\site-packages\wfastcgi.py", line 594, in get_wsgi_handler
    handler = handler()
TypeError: wsgi_app() missing 2 required positional arguments: 'environ' and 'start_response'


StdOut: 

StdErr:
问题

  • 如何传递2个函数参数以及传递什么
  • 用函数启动模块似乎不是一个好主意。我可以用类来代替吗?如果是这样,我应该如何更改此行的
    web.config
  • 
    
    我的第一个建议(如果您还没有这样做)是在IIS中配置失败的请求跟踪。然后,每当您的WSGI处理程序(即my_app.WSGI_app)在开发过程中崩溃时,IIS都会生成一个漂亮的.xml文件,您可以在浏览器中查看该文件,详细说明发生了什么,包括Python回溯,即使您的IIS最终配置为在此实例中生成“500-内部服务器错误”

    接下来,正如丹尼尔·罗斯曼(Daniel Roseman)已经建议的那样,改变

    <add key="WSGI_HANDLER" value="my_app.wsgi_app()" />
    

    希望这有帮助。

    错误输出中的最后几行树是什么意思?您不需要调用函数,WSGI会调用,所以您不需要担心它传递了什么。Python在顶级函数方面做得非常好;这里不需要上课。最后,该代码不会给出该错误;请发布实际代码。哦,你是对的。我想是index.php搞乱了默认的文档处理。已更新错误。请尝试从该配置值中删除括号。
    <add key="WSGI_HANDLER" value="my_app.wsgi_app()" />
    
    <add key="WSGI_HANDLER" value="my_app.wsgi_app" />
    
    File "<the path to ...\python\pythonXX\lib\site-packages\wfastcgi.py on your system>", line 372, in send_response
    raise TypeError("content must be encoded before sending: %r" % content)
    TypeError: content must be encoded before sending: 'Hello world!\n'
    
    def wsgi_app(environ, start_response):
        status = "200 OK"
        headers = [("Content-Type", "text/plain; charset=utf-8")]
        start_response(status, headers)
    
        response = ["Hello world!\n"]
    
        return (line.encode("utf-8") for line in response)