【发布时间】:2017-03-24 20:00:51
【问题描述】:
尝试在 Azure 云上部署 Python 应用。使用 python3.5.2x64 从 Cookiecutter template 创建 WebApp。使用模板中预配置的 web.config 我遇到 500 错误:<handler> scriptProcessor could not be found in <fastCGI> application configuration。
我的web.config 文件:
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
<appSettings>
<add key="PYTHONPATH" value="D:\home\site\wwwroot"/>
<add key="WSGI_HANDLER" value="webapp.wsgi_app"/>
<add key="WSGI_LOG" value="D:\home\LogFiles\python.log"/>
</appSettings>
<system.webServer>
<httpErrors errorMode="Detailed" />
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<add name="Python FastCGI"
path="*"
verb="*"
modules="FastCgiModule"
scriptProcessor="D:\home\Python35\python.exe|D:\home\Python35\wfastcgi.py"
resourceType="Unspecified"
requireAccess="Script" />
</handlers>
</system.webServer>
</configuration>
我的webapp.py:
def wsgi_app(environ, start_response):
status = '200 OK'
response_headers = [('Content-type', 'text/plain')]
start_response(status, response_headers)
response_body = 'Hello World'
yield response_body.encode()
if __name__ == '__main__':
from wsgiref.simple_server import make_server
httpd = make_server('localhost', 5555, wsgi_app)
httpd.serve_forever()
使用 Azure 中的 Django 应用程序没有帮助,因为它已经过时(使用不受支持的 Microsoft.Diagnostics,引发 AttributeError: 'module' object has no attribute 'get_virtualenv_handler')。
任何建议我做错了什么?谢谢。
更新。
花了一些时间后,我发现所有都适用于本机安装的 Python(2 或 3,没关系),因此 IIS 似乎没有看到或 smth 我的 Python 扩展(从 Azure 门户安装)。然而,即使使用原生 Python,它也不能立即工作,而是首先抛出 TypeError: source code string cannot contain null bytes (Python 3.4) 或 AttributeError: 'module' object has no attribute 'wsgi_app' (Python 2.7)。大约 15 分钟后,它神奇地开始工作。我所做的只是更改 Hello World! 字符串。
【问题讨论】:
-
但是您是想像应用程序一样部署它,还是在天蓝色的虚拟机中部署它?
-
@Hackerman 喜欢一个应用程序,我的意思是我选择 Web App,然后通过 Git 或 VS Code Online 添加这两个文件并重新启动。
-
@MartynC 是的,我阅读了本教程,但我试图不使用虚拟环境。所以我有相同的
app.py(在我的情况下是webapp.py),但显着减少了web.config,其次是this。 -
是的....但是您知道网络应用程序的功能限制吗?
标签: python azure iis fastcgi wsgi