django web-config azure给出错误“ RuntimeError:populate()不重入”

时间:2018-07-18 20:55:28

标签: django azure web-config

我通过GitHub将本地开发的Django Web应用程序部署到Azure中,当我尝试运行URL时,在web.config文件中收到以下错误

 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:

这是我的web.config文件:

    <?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>

我的代码是否有问题,还是需要安装一些其他要求?尝试在Azure中运行django Web应用程序时出现错误,在本地运行我的Web应用程序时运行正常。

1 个答案:

答案 0 :(得分:0)

  

RuntimeError:populate()不能重入

我将django应用程序部署为天蓝色,但没有重现您的问题。据我所知,这意味着配置之一不正确或缺少必需的库,它将引起此填充错误。

我建议您将以下代码添加到wsgi.py文件中,并记录真正的错误,然后可以进行检查。

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)

更多解决方案,请参考以下主题:

1。Django populate() isn't reentrant

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

希望它对您有帮助。