Error reading WSGI handler. Deploy django for an azure web app.

Very related to this post, but I don't have the privilege to comment there, so I had to make a new post. Deploy simple Django VS2017 app with Azure error - server

I followed the Silencer tutorial and I am getting this error from \ 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>

      

I have installed python360x64 as an extension in azure portal, I use this https://github.com/Azure/azure-sdk-for-python/blob/master/examples/AzureResourceViewer/ptvs_virtualenv_proxy.py And my 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>

      

The my / env / python version is python360x64. Any help is appreciated!

+3


source to share


3 answers


I am getting the same errors in python 3.4. For python 2.7, there is an activated_this.py script that might help in some way.

Just put activ_this.py from python 2.7 virtual environment into a folder. \ env \ Scripts and change the path in web.config to point to activate_this.py.



Seems to have worked. I'm just not sure which version of python I'm using now as 2.7 is still present on the system.

0


source


I had the same problem and finally got it fixed by changing this line in app config:

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

      

:



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

      

myProject is the name of my django project, so you must provide the name of your project.

0


source


I had the same problem, I was wrong in WSGI_HANDLER as python 3.4 should be:

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

      

0


source







All Articles