0

I deployed my locally developed Django web app into azure through GitHub and when i try to run the URL,i get the following error in web.config file

 Error occurred while reading WSGI handler:

Traceback (most recent call last):
  File "D:\home\python364x64\wfastcgi.py", line 791, in main
    env, handler = read_wsgi_handler(response.physical_path)
  File "D:\home\python364x64\wfastcgi.py", line 633, in read_wsgi_handler
    handler = get_wsgi_handler(os.getenv("WSGI_HANDLER"))
  File "D:\home\python364x64\wfastcgi.py", line 605, in get_wsgi_handler
    handler = handler()
  File ".\ptvs_virtualenv_proxy.py", line 107, in get_venv_handler
    handler = get_wsgi_handler(os.getenv('WSGI_ALT_VIRTUALENV_HANDLER'))
  File ".\ptvs_virtualenv_proxy.py", line 65, in get_wsgi_handler
    handler = handler()
  File "D:\home\site\wwwroot\env\lib\site-packages\django\core\wsgi.py", line 12, in get_wsgi_application
    django.setup(set_prefix=False)
  File "D:\home\site\wwwroot\env\lib\site-packages\django\__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "D:\home\site\wwwroot\env\lib\site-packages\django\apps\registry.py", line 81, in populate
    raise RuntimeError("populate() isn't reentrant")
RuntimeError: populate() isn't reentrant


StdOut: 

StdErr:

this is my web.config file:

    <?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0" />
      <customErrors mode="Off" />
    </system.web>
    <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_venv_handler()" />
      <add key="PYTHONPATH" value="D:\home\site\wwwroot" />
      <add key="DJANGO_SETTINGS_MODULE" value="FinTech.settings" />
      <add key="WSGI_LOG" value="D:\home\LogFiles\wfastcgi.log"/>
    </appSettings>
    <system.webServer>
      <httpErrors errorMode="Detailed" />
      <handlers>
        <add name="PythonHandler" path="*" verb="*" modules="FastCgiModule" scriptProcessor="D:\home\python364x64\python.exe|D:\home\python364x64\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>

Is there something wrong with my code or do i need to install some additional requirements? I am getting this error while trying to run the django web app in Azure, locally when i run my web app it works fine.

Jay Gong
  • 23,163
  • 2
  • 27
  • 32
PKK
  • 31
  • 4
  • Suggesting you to check this GitHub link below and make sure your web.config and all other files dont have any conflicting data etc, https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/app-service/web-sites-python-configure.md – Zahid Faroq Jul 18 '18 at 21:35
  • I tried it but still no change in the error. When i opened console of my azure app and run "manage.py runserver" it gave me an error as "Traceback (most recent call last): File "D:\home\site\wwwroot\manage.py", line 12, in "Couldn't import Django. Are you sure it's installed and " ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?" – PKK Jul 19 '18 at 20:30

1 Answers1

0

RuntimeError: populate() isn't reentrant

I deploy my django app to azure and didn't reproduce your issue. Per my knowledge,this means one of configuration is not correct or required library missing it will rise this populate error.

I suggest you adding below code into your wsgi.py file and the real error should be logged,then you could check it.

import os
import time
import traceback
import signal
import sys
from django.core.wsgi import get_wsgi_application

try:
    application = get_wsgi_application()
    print 'WSGI without exception'
except Exception:
    print 'handling WSGI exception'
    # Error loading applications
    if 'mod_wsgi' in sys.modules:
        traceback.print_exc()
        os.kill(os.getpid(), signal.SIGINT)
        time.sleep(2.5)

More solutions,please refer to these threads:

1.Django populate() isn't reentrant

2.Django stops working with RuntimeError: populate() isn't reentrant

Hope it helps you.

Jay Gong
  • 23,163
  • 2
  • 27
  • 32
  • Thank you for your reply. I tried adding the above code to my wsgi.py file but still it gave me the same error "RuntimeError: populate() isn't reentrant" and i also referred to the above links butt none of them worked. – PKK Jul 19 '18 at 15:25