【问题标题】:Error occurred while reading WSGI handler - Deploy django to azure web app读取 WSGI 处理程序时发生错误 - 将 django 部署到 azure Web 应用程序
【发布时间】:2017-07-28 08:43:53
【问题描述】:

与这篇文章非常相关,但我没有在那里发表评论的特权,所以我不得不发一个新帖子。 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。 任何帮助表示赞赏!

【问题讨论】:

  • 所以我在 ptvs_virtualenv_proxy.py 中打开 python.exe 为 latin-1 时搜索了一些并更改了编码,我尝试了 utf-8 但这也不起作用。使用 latin-1 我收到错误:文件“.\ptvs_virtualenv_proxy.py”,第 31 行,在 execfile exec(code, global_dict) ValueError: source code string cannot contain null bytes

标签: django azure azure-web-app-service


【解决方案1】:

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

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

到这里:

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

myProject 是我的 django 项目的名称,所以你应该输入你的项目名称。

【讨论】:

    【解决方案2】:

    我在 python 3.4 中遇到了同样的错误。对于 python 2.7,有一个 activate_this.py 脚本,它可以在某种程度上提供帮助。

    只需将 python 2.7 虚拟环境中的 activate_this.py 放在 .\env\Scripts 文件夹中,并将 web.config 中的路径更改为指向 activate_this.py。

    它似乎工作。我只是不确定我现在使用的是哪个版本的 python,因为系统上仍然存在 2.7。

    【讨论】:

      【解决方案3】:

      我有同样的问题,我在 WSGI_HANDLER 中错了,因为 python 3.4 必须是:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-11-23
        • 1970-01-01
        • 2011-01-20
        • 2019-06-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-21
        相关资源
        最近更新 更多