iHemant
iHemant

Reputation: 11

Error occured while reading WSGI handler. ModuleNotFoundError' while hosting DJango on IIS. Can't find settings

I am doing this for the first time. I am trying to host my Django rest app on Windows IIS server. I have followed this tutorial https://medium.com/@Jonny_Waffles/deploy-django-on-iis-def658beae92 but I am getting the following error. Does it have to do something with my conda environment? I haven't used any config file. I've set the environment variables in the system variables instead.

In my settings.py

WSGI_APPLICATION = 'webapi.wsgi.application'

IN wsgi.py

import os

from django.core.wsgi import get_wsgi_application
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'webapi.settings')

    application = get_wsgi_application()
Error occurred while reading WSGI handler:

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\envs\api_env\lib\site-packages\wfastcgi.py", line 791, in main
    env, handler = read_wsgi_handler(response.physical_path)
  File "C:\ProgramData\Anaconda3\envs\api_env\lib\site-packages\wfastcgi.py", line 633, in read_wsgi_handler
    handler = get_wsgi_handler(os.getenv("WSGI_HANDLER"))
  File "C:\ProgramData\Anaconda3\envs\api_env\lib\site-packages\wfastcgi.py", line 616, in get_wsgi_handler
    raise ValueError('"%s" could not be imported%s' % (handler_name, last_tb))
ValueError: "webapi.wsgi.application" could not be imported: Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\envs\api_env\lib\site-packages\wfastcgi.py", line 600, in get_wsgi_handler
    handler = __import__(module_name, fromlist=[name_list[0][0]])
  File "C:\inetpub\wwwroot\webapi\webapi\wsgi.py", line 16, in <module>
    application = get_wsgi_application()
  File "C:\ProgramData\Anaconda3\envs\api_env\lib\site-packages\django\core\wsgi.py", line 12, in get_wsgi_application
    django.setup(set_prefix=False)
  File "C:\ProgramData\Anaconda3\envs\api_env\lib\site-packages\django\__init__.py", line 19, in setup
    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
  File "C:\ProgramData\Anaconda3\envs\api_env\lib\site-packages\django\conf\__init__.py", line 79, in __getattr__
    self._setup(name)
  File "C:\ProgramData\Anaconda3\envs\api_env\lib\site-packages\django\conf\__init__.py", line 66, in _setup
    self._wrapped = Settings(settings_module)
  File "C:\ProgramData\Anaconda3\envs\api_env\lib\site-packages\django\conf\__init__.py", line 157, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "C:\ProgramData\Anaconda3\envs\api_env\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'C:\\inetpub\\wwwroot\\webapi\\webapi\\settings'



StdOut: 

StdErr:

Upvotes: 0

Views: 4614

Answers (1)

Jakob M&#252;ller
Jakob M&#252;ller

Reputation: 91

For me the problem that lead to this same error message was that in the settings of my FastCGI handler the environment variable DJANGO_SETTINGS_MODULE was wrong.

it has to be a module path, i.e. MyProject.settings instead of C:\inetpub\wwwroot\MyProject\MyProject\settings.py as I assume was in your case.

so for you: DJANGO_SETTINGS_MODULE = webapi.settings

Upvotes: 1

Related Questions