Forums

Error running WSGI application ImportError: win32 only

Hello,

I am getting an error which seems quite common. However, I don't seem to be able to fix it by following the answers given in the forum. Could someone help me with this issue?

This is my WSGI file:

import os
import sys

path = '/home/mRayhoon/IESEG8'
if path not in sys.path:
    sys.path.append(path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'IESEG8.settings'
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

This is the error:

Error running WSGI application
ImportError: win32 only

File "/var/www/mrayhoon_pythonanywhere_com_wsgi.py", line 16, in <module>
application = get_wsgi_application()
File "/home/mRayhoon/.virtualenvs/myenv/lib/python3.9/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application django.setup(set_prefix=False)
File "/home/mRayhoon/.virtualenvs/myenv/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/mRayhoon/.virtualenvs/myenv/lib/python3.9/site-packages/django/apps/registry.py", line 116, in populate app_config.import_models()
File "/home/mRayhoon/.virtualenvs/myenv/lib/python3.9/site-packages/django/apps/config.py", line 304, in import_models self.models_module = import_module(models_module_name)
File "/home/mRayhoon/IESEG8/base/models.py", line 1, in <module>
from asyncio.windows_events import NULL
File "/usr/local/lib/python3.9/asyncio/windows_events.py", line 6, in <module>
raise ImportError('win32 only')

Thanks in advance.

[edit by admin: formatting]

The error is telling you (perhaps a bit cryptically) that the library you're trying to import from, asyncio.windows_events, is only supported on Windows. When you run your code on PythonAnywhere, it's running on a Linux system rather than on Windows.

The NULL name that you're trying to import doesn't look like it's necessarily windows-specific, though, at least from its name. Are you doing anything in your code that's tied to Windows?

Thank you so much. I just checked, in my models.py, I have:

from asyncio.windows_events import NULL

At first glance, it seems like an unnecessary import. However, when I comment it out, I get the following error (the following is only part of the error):

File "C:\Users\moham\OneDrive\0 myCodes\IESEG8\base\models.py", line 179, in Profile
User, null=True, blank=True, on_delete=models.CASCADE, default=NULL) 
NameError: name 'NULL' is not defined

Anyways, I somehow managed to get rid of that import and now the error is gone. :) Thanks again.

What do you have that as default value on the mode filed? NULL in tha context is just integer 0 but as you import it from asyncio.windows_events it is raising See https://github.com/python/cpython/blob/3.10/Lib/asyncio/windows_events.py#L5 and https://github.com/python/cpython/blob/3.10/Lib/asyncio/windows_events.py#L36