【问题标题】:wfastcgi cannot find flask app in IIS on Win7wfastcgi 在 Win7 上的 IIS 中找不到烧瓶应用程序
【发布时间】:2017-04-06 14:13:26
【问题描述】:

我正在尝试在 IIS6 上为 Windows 7 设置 wfastcgi,但它找不到我的“app.py”文件。我使用http://netdot.co/2015/03/09/flask-on-iis/ 作为我的设置方向。以下是我收到的错误消息。在我寻找答案的过程中,最可能的解决方案是权限问题,我相信我正确地授予了权限,但仍然没有运气。

Error occurred while reading WSGI handler:
Traceback (most recent call last):
File "C:\inetpub\wwwroot\Flask_Proj\wfastcgi.py", line 712, in main env, handler = read_wsgi_handler(response.physical_path)
File "C:\inetpub\wwwroot\Flask_Proj\wfastcgi.py", line 569, in read_wsgi_handler return env, get_wsgi_handler(handler_name)
File "C:\inetpub\wwwroot\Flask_Proj\wfastcgi.py", line 552, in get_wsgi_handler raise ValueError('"%s" could not be imported' % handler_name)
ValueError: app.app could not be imported StdOut: StdErr: 

这是Web.config 文件

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <appSettings>
    <add key="WSGI_HANDLER" value="app.app" />
    <add key="PYTHONPATH" value="C:\inetpub\wwwroot\Flask_Proj\" />
  </appSettings>

    <system.webServer>
        <handlers accessPolicy="Read, Script">
            <add name="FlaskHandler" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:\Python34\python.exe|C:\inetpub\wwwroot\Flask_Proj\wfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
        </handlers>
    </system.webServer>
    </configuration>

另外,为了让您的生活更轻松,这里是 wfastcgi.py 文件的代码的 sn-p:

def get_wsgi_handler(handler_name):
    if not handler_name:
        raise Exception('WSGI_HANDLER env var must be set')

    if not isinstance(handler_name, str):
        if sys.version_info >= (3,):
            handler_name = handler_name.decode(sys.getfilesystemencoding())
        else:
            handler_name = handler_name.encode(sys.getfilesystemencoding())

    module_name, _, callable_name = handler_name.rpartition('.')
    should_call = callable_name.endswith('()')
    callable_name = callable_name[:-2] if should_call else callable_name
    name_list = [(callable_name, should_call)]
    handler = None

    while module_name:
        try:
            handler = __import__(module_name, fromlist=[name_list[0][0]])
            for name, should_call in name_list:
                handler = getattr(handler, name)
                if should_call:
                    handler = handler()
            break
        except ImportError:
            module_name, _, callable_name = module_name.rpartition('.')
            should_call = callable_name.endswith('()')
            callable_name = callable_name[:-2] if should_call else callable_name
            name_list.insert(0, (callable_name, should_call))
            handler = None

    if handler is None:
        raise ValueError('"%s" could not be imported' % handler_name)

    return handler

以下是我发现的一些类似问题的链接:

https://www.experts-exchange.com/questions/28937664/Installing-Flask-app-on-IIS7.html

https://social.msdn.microsoft.com/Forums/en-US/3113de0a-3385-48dc-872b-d70deac071c6/azure-flask-python-could-not-be-imported-error-500-azure-website?forum=windowsazurewebsitespreview

【问题讨论】:

    标签: python iis flask iis-6 wfastcgi


    【解决方案1】:

    我发现我做错了什么。这是一个愚蠢的错误,但根据我的搜索,我可能不是唯一一个。我安装了 python,但我没有 pip install Flask。一旦我开始运行,其他一切就更容易弄清楚了。

    【讨论】:

      猜你喜欢
      • 2018-06-24
      • 1970-01-01
      • 1970-01-01
      • 2013-09-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-18
      • 1970-01-01
      • 2014-11-17
      相关资源
      最近更新 更多