Microsoft Azure 上的 Python FastCGI 错误

标签 python azure iis fastcgi wsgi

尝试在 Azure 云上部署 Python 应用程序。从 Cookiecutter 创建 Web 应用程序 template使用 python3.5.2x64。使用预配置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' )。

有什么建议我做错了吗?谢谢。

更新。 经过一段时间后,我发现所有这些都适用于 native 安装的 Python(2 或 3,无关紧要),因此 IIS 似乎看不到或无法看到我的 Python 扩展(顺便说一句,从 Azure Portal 安装)。然而,即使使用 native 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! 字符串。

最佳答案

不,解决方案非常合乎逻辑,但并不明显(正如我认为的)。我刚刚将处理程序添加到 Azure 门户上的 Web 应用程序设置(Web 应用程序 -> 应用程序设置 -> 处理程序映射),一切都非常顺利!

关于Microsoft Azure 上的 Python FastCGI 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40533577/

相关文章:

windows - 从 IIS 上的命令行列出所有托管网站

python - "The following environment does not have an entry for the variable"在 FiniteHorizo​​nLinearQuadraticRegulator 的上下文中意味着什么

python - 数字打印机,随机整数不起作用

python - 在 python 中矢量化蒙特卡洛模拟

python - python : get indices of a sub-list in a larger list 中的列表匹配

azure - 使用 AzureADB2C 和 B2B 进行单点登录

iis - 漂亮的实时网络跟踪

Azure Maps Search API 的响应语言并不总是英语

python - 使用 python 在 azure 函数中并行调用方法

iis - 如何在远程 IIS Web 服务器上创建 Mercurial 存储库