I was setting up all paths in my web.config file and configuring everything in IIS (on Windows Server 2012 R2). When I was done I started the server and accessed the website. But while doing so I got this following error message:
Error occurred while reading WSGI handler:
Traceback (most recent call last):
File "C:\inetpub\wwwroot\djangoapp\wfastcgi.py", line 711, in main
env, handler = read_wsgi_handler(response.physical_path)
File "C:\inetpub\wwwroot\djangoapp\wfastcgi.py", line 568, in read_wsgi_handler
return env, get_wsgi_handler(handler_name)
File "C:\inetpub\wwwroot\djangoapp\wfastcgi.py", line 551, in get_wsgi_handler
raise ValueError('"%s" could not be imported' % handler_name)
ValueError: "django.core.wsgi.get_wsgi_application()" could not be imported
StdOut:
StdErr:
Web.config (file):
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="Python FastCGI"
path="*"
verb="*"
modules="FastCgiModule"
scriptProcessor="C:\Python34\python.exe|C:\inetpub\wwwroot\djangoapp\wfastcgi.py"
resourceType="Unspecified"
requireAccess="Script" />
</handlers>
</system.webServer>
<appSettings>
<add key="WSGI_HANDLER" value="django.core.wsgi.get_wsgi_application()" />
<add key="PYTHONPATH" value="C:\Python34\python.exe" />
<add key="WSGI_RESTART_FILE_REGEX" value=".*((\.py)|(\.config))$" />
<add key="DJANGO_SETTINGS_MODULE" value="djangoapp.settings" />
</appSettings>
</configuration>
I don't understand why this error occurs. Does anyone has a clue how to solve this?
I see this problem a lot on the web. The problem what you have here is that you have 2 versions of Python on your machine. Make sure you have everything installed for both versions. For example Python version 3.4: py -m pip install django and for Python version 3.6: just pip install django according how your environment variables are set of course. Please make sure that everything is downloaded ok. Also note that for both versions you have to enter these commands as well to make it work:
For version 3.6 (in my case):
pip install --upgrade wheel
pip install wfastcgi
wfastcgi-enable
And for version 3.4 (in my case):
py -m pip install --upgrade wheel
py -m pip install wfastcgi
wfastcgi-enable
Notice that both versions have their own wfastcgi.
Here is the difference between us.
<add key="WSGI_HANDLER" value="django.core.handlers.wsgi.WSGIHandler()" />
<add key="PYTHONPATH" value="[PATH_OF_DJANGOAPP]" />