3

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

I followed Silencer's tutorial there 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 am using 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>

My /env/ python version is python360x64. Any help appreciated!

1
  • So I googled some and changed the encoding when opening python.exe in ptvs_virtualenv_proxy.py to latin-1, I tried utf-8 but that didn't work either. With latin-1 I get the error: File ".\ptvs_virtualenv_proxy.py", line 31, in execfile exec(code, global_dict) ValueError: source code string cannot contain null bytes Commented Jul 28, 2017 at 9:36

3 Answers 3

1

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

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

to this:

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

myProject is the name of my django project so you should put the your project's name.

Sign up to request clarification or add additional context in comments.

Comments

0

I get the same errors in python 3.4. For python 2.7 there is an activate_this.py script, which can help in some way.

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

It seems to work. I am just not sure which version of python I am using now as 2.7 is still present on the system.

Comments

0

I had same problem, I was wrong in WSGI_HANDLER, for python 3.4 must be:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.