django - 读取 WSGI 处理程序时发生错误 - 将 django 部署到 azure web 应用程序

标签 django azure azure-web-app-service

与这篇文章非常相关,但我没有在那里发表评论的权限,所以我不得不发表一篇新文章。 Deploy a simple VS2017 Django app to Azure - server error

我按照 Silencer 的教程进行操作,但从\LogFiles\wfastcgi.log 收到此错误:

2017-07-28 08:28:57.746719: Activating virtualenv with D:\home\site\wwwroot\env\Scripts\python.exe
2017-07-28 08:28:57.777987: Error occurred while reading WSGI handler:

Traceback (most recent call last):
  File "D:\home\python360x64\wfastcgi.py", line 791, in main
    env, handler = read_wsgi_handler(response.physical_path)
  File "D:\home\python360x64\wfastcgi.py", line 633, in read_wsgi_handler
    handler = get_wsgi_handler(os.getenv("WSGI_HANDLER"))
  File "D:\home\python360x64\wfastcgi.py", line 605, in get_wsgi_handler
    handler = handler()
  File ".\ptvs_virtualenv_proxy.py", line 99, in get_virtualenv_handler
    execfile(activate_this, dict(__file__=activate_this))
  File ".\ptvs_virtualenv_proxy.py", line 27, in execfile
    code = f.read()
  File "D:\Repos\azure-python-siteextensions\source_packages\python.3.6.0\tools\Lib\encodings\cp1252.py", line 23, in decode
UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 2: character maps to <undefined>

我已经在azure门户中安装了python360x64作为扩展,我正在使用这个https://github.com/Azure/azure-sdk-for-python/blob/master/examples/AzureResourceViewer/ptvs_virtualenv_proxy.py 还有我的 web.config:

<configuration>
  <system.diagnostics>
    <trace>
      <listeners>
        <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
          <filter type="" />
        </add>
      </listeners>
    </trace>
  </system.diagnostics>
  <appSettings>
    <add key="WSGI_ALT_VIRTUALENV_HANDLER" value="django.core.wsgi.get_wsgi_application()" />
    <add key="WSGI_ALT_VIRTUALENV_ACTIVATE_THIS" value="D:\home\site\wwwroot\env\Scripts\python.exe" />
    <add key="WSGI_HANDLER" value="ptvs_virtualenv_proxy.get_virtualenv_handler()" />
    <add key="PYTHONPATH" value="D:\home\site\wwwroot" />
    <add key="DJANGO_SETTINGS_MODULE" value="DjangoWebProject.settings" />
    <add key="WSGI_LOG" value="D:\home\LogFiles\wfastcgi.log"/>
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <handlers>
      <add name="Python FastCGI" path="handler.fcgi" verb="*" modules="FastCgiModule" scriptProcessor="D:\home\python360x64\python.exe|D:\home\python360x64\wfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
    </handlers>
    <rewrite>
      <rules>
        <rule name="Static Files" stopProcessing="true">
          <conditions>
            <add input="true" pattern="false" />
          </conditions>
        </rule>
        <rule name="Configure Python" stopProcessing="true">
          <match url="(.*)" ignoreCase="false" />
          <conditions>
            <add input="{REQUEST_URI}" pattern="^/static/.*" ignoreCase="true" negate="true" />
          </conditions>
          <action type="Rewrite" url="handler.fcgi/{R:1}" appendQueryString="true" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

我的/env/python 版本是 python360x64。 任何帮助表示赞赏!

最佳答案

我遇到了同样的问题,最后通过更改应用程序配置中的这一行来解决:

<add key="WSGI_HANDLER" value="ptvs_virtualenv_proxy.get_virtualenv_handler()" />

对此:

<add key="WSGI_HANDLER" value="myProject.wsgi.application" />

myProject 是我的 django 项目的名称,因此您应该输入您的项目的名称。

关于django - 读取 WSGI 处理程序时发生错误 - 将 django 部署到 azure web 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45368847/

相关文章:

python - 以编程方式将图像保存到 Django ImageField 会创建图像的无限循环

python - TransactionManagementError - 当 'atomic' block 处于事件状态时,这是被禁止的

jquery - Django - CreateView 不保存带有嵌套表单集的表单

azure - 我可以使用哪些 Azure 媒体服务 V3 转换预设来生成 .webm 输出

azure - 如何在 Azure 应用服务中创建虚拟目录并部署包

javascript - 将 JavaScript date() 转换为 Python Django models.DateTimeField

deployment - Eclipse - 为什么 Azure 部署需要这么长时间

azure - 将 Azure 服务总线替换为 Blob 存储

c# - ASP.NET Core + ApplicationInsights 将错误记录为跟踪

c# - Botframework Web 应用程序 Azure IDX20803 : Unable to obtain configuration from: '[PII is hidden]