I've published my Django application to IIS after upgrading Django installation locally , in my virtualenv, and on the server. I just finished migrating my application from Django 1.6 to 1.9 and in DEBUG everything seems to work fine. The published application fails to run:
Error occurred while reading WSGI handler:
Traceback (most recent call last):
File "c:\python27\Lib\site-packages\wfastcgi.py", line 791, in main
env, handler = read_wsgi_handler(response.physical_path)
File "c:\python27\Lib\site-packages\wfastcgi.py", line 633, in read_wsgi_handler
handler = get_wsgi_handler(os.getenv("WSGI_HANDLER"))
File "c:\python27\Lib\site-packages\wfastcgi.py", line 605, in get_wsgi_handler
handler = handler()
File ".\ptvs_virtualenv_proxy.py", line 102, in get_virtualenv_handler
handler = get_wsgi_handler(os.getenv('WSGI_ALT_VIRTUALENV_HANDLER'))
File ".\ptvs_virtualenv_proxy.py", line 76, in get_wsgi_handler
handler = getattr(handler, name)
AttributeError: 'module' object has no attribute 'wsgi'
Cant find the problem
I vaguely recall the WSGI handler stuff changing at some point in a Django update?
I created a new django project, and the handler looks like: DjangoWebProject7.wsgi.application (as seen in DjangoWebProject7/settings.py)
And there's a DjangoWebProject7/wsgi.py that looks like this:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "DjangoWebProject7.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
If your WSGI_HANDLER doesn't look like that in your web.config or you don't have a wsgi.py, then that would be the first thing to try.
My wsgi.py looks the same. I had it located here: project_folder\django_application_folder\wsgi.py, this was the project structure created by older versions of Django. I tried putting a copy of wsgi.py under the project root folder, didn't make a difference.
This is in my web.config:
<appSettings>
<add key="WSGI_ALT_VIRTUALENV_HANDLER" value="django.core.wsgi.get_wsgi_application()" />
<add key="WSGI_ALT_VIRTUALENV_ACTIVATE_THIS" value="C:\Python Packages\DjangoProject\env\Scripts\activate_this.py" />
<add key="WSGI_HANDLER" value="ptvs_virtualenv_proxy.get_virtualenv_handler()" />
<add key="PYTHONPATH" value="C:\Python Packages\DjangoProject" />
<add key="DJANGO_SETTINGS_MODULE" value="DjangoProject.settings" />
</appSettings>
Update:
I am using Visual studio 2015 by the way, not sure if this matters. Perhaps my ptvs_virtualenv_proxy.py is outdated?
My ptvs_virtualenv_proxy.py script seems to be up to date. I have tried importing the get_wsgi_handler() method from this file in an interactive session, and when I pass it the string 'django.core.wsgi.get_wsgi_application()' (same as in my web.config) it successfully returns a WSGI handler object. But strangely the same method raises an exception when it's called by IIS/wfastcgi.py.
I can confirm that the get_wsgi_handler() method is passed the same handler_name when it is called from IIS/wfastcgi.py.
I found the problem! My virtualenv contained files from an earlier version of Django because Publishing from Visual Studio did not delete remote files that no longer exist in my project's virtualenv. I just enabled deleting of remote files in my publish config and then it worked.
I found the problem! My virtualenv contained files from an earlier version of Django because Publishing from Visual Studio did not delete remote files that no longer exist in my project's virtualenv. I just enabled deleting of remote files in my publish config and then it worked.
Hello. could you help me how to fix it. thnak you very much