【发布时间】:2016-10-17 16:55:34
【问题描述】:
我已经设置了一个 virtualenv 来运行一个烧瓶服务器。我已按照步骤设置 wfastcgi 以使用 iis。它似乎正在工作,因为我能够访问 python 应用程序,但会打印一个 python 错误堆栈。
读取 WSGI 处理程序时发生错误:
Traceback (most recent call last):
File "c:\python27\lib\site-packages\wfastcgi.py", line 793, in main
env, handler = read_wsgi_handler(response.physical_path)
File "c:\python27\lib\site-packages\wfastcgi.py", line 635, in read_wsgi_handler
handler = get_wsgi_handler(os.getenv("WSGI_HANDLER"))
File "c:\python27\lib\site-packages\wfastcgi.py", line 618, in get_wsgi_handler
raise ValueError('"%s" could not be imported%s' % (handler_name, last_tb))
ValueError: "flask_app.application()" could not be imported: Traceback (most recent call last):
File "c:\python27\lib\site-packages\wfastcgi.py", line 602, in get_wsgi_handler
handler = __import__(module_name, fromlist=[name_list[0][0]])
File ".\flask_app.py", line 7, in <module>
from app import app as application
File ".\app\__init__.py", line 67, in <module>
from flask_restless import APIManager
ImportError: No module named flask_restless
我认为这与我安装 flask_restless 的方式有关。我使用
安装它pip install -e git://github.com/jfinkels/flask-restless.git#egg=flask_restless
这似乎没有将 flask_restless 添加到 Lib/site-packages 目录。但是当我手动运行应用程序时,这不是问题。
这是我的 web.config:
<configuration>
<system.webServer>
<handlers>
<add name="Python FastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:\Python27\python.exe|C:\Python27\Lib\site-packages\wfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
</handlers>
</system.webServer>
<appSettings>
<!-- Required settings -->
<add key="WSGI_HANDLER" value="flask_app.application()" />
<add key="PYTHONPATH" value="C:\www\flask_app\virtualenv\src;C:\www\flask_app\virtualenv\Lib\site-packages;C:\www\flask_app\app" />
<!-- Optional settings -->
<add key="WSGI_LOG" value="C:\inetpub\logs\wsgi.log" />
<add key="WSGI_RESTART_FILE_REGEX" value=".*((\.py)|(\.config))$" />
</appSettings>
</configuration>
而我的flask_app.py如下:
this_file = 'C:/www/flask_app/virtualenv/Scripts/activate_this.py'
with open(this_file) as f:
code = compile(f.read(), this_file, 'exec')
exec(code)
from app import app as application
【问题讨论】:
标签: python iis virtualenv fastcgi