读取WSGI处理程序时出错 - 将django部署到azure Web应用程序

时间:2017-07-28 08:43:53

标签: django azure azure-web-sites 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>

我已经安装了python360x64作为azure portal的扩展,我正在使用这个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。 任何帮助表示赞赏!

3 个答案:

答案 0 :(得分:0)

我在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仍然存在于系统中。

答案 1 :(得分:0)

我遇到了同样的问题,最后通过在app config中更改此行来解决此问题:

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

到此:

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

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

答案 2 :(得分:0)

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

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