作为一个刚完成代码学院免费课程的完整python新手,我按照这是Python wfastcgi 2.2页上的说明成功地在IIS上安装了python处理程序。
然后,我按照下面的代码创建了一个python文件(模块) my_app.py ( web.config )(我在某些地方对其进行了修改):
def wsgi_app(environ, start_response):
status = '200 OK'
response_headers = [('Content-type','text/plain')]
start_response(status, response_headers)
return ['Hello world!\n']在导航到本地主机站点时,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:问题
web.config:<add key="WSGI_HANDLER" value="my_app.wsgi_app()" />发布于 2017-02-16 07:13:29
我的第一个建议(如果您还没有这样做)是在IIS中配置失败的请求跟踪。然后,当您的WSGI处理程序(即my_app.wsgi_app)在开发过程中崩溃时,IIS将生成一个很好的.xml文件,您可以在浏览器中查看该文件,详细说明所发生的事情,包括Python,即使您的IIS最终被配置为在此实例中生成“500-Internalserver错误”。
接下来,正如丹尼尔·罗斯曼所建议的,改变
<add key="WSGI_HANDLER" value="my_app.wsgi_app()" />至
<add key="WSGI_HANDLER" value="my_app.wsgi_app" />在您的web.config文件中,wfastcgi.py将能够找到并调用您的wsgi_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'这个编码问题的解决方案在David Beazley的wsgiref部分(我的副本中第541页)中的"Python:基本参考“中进行了描述。我建议你尝试以下几种方法:
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)希望这能有所帮助。
https://stackoverflow.com/questions/37191453
复制相似问题