Type Error in get_wsgi_application() in Django 2.x with python3
Asked Answered
P

1

2

I am migrating a web application from Django 1.9 to 2.0.2. The code is

import os
import sys

path = '/mypath'
if path not in sys.path:
    sys.path.append(path)

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Myapplication.settings")


from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

However, if I try to execute this, I get an error:

File "/home/.../wsgi.py", line 29, in <module>
application = get_wsgi_application()
File "/home/.../virtual/lagerthree/lib/python3.5/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
return WSGIHandler()
File "/home/.../lagerthree/lib/python3.5/site-packages/django/core/handlers/wsgi.py", line 140, in __init__
self.load_middleware()
File "/home/.../virtual/lagerthree/lib/python3.5/site-packages/django/core/handlers/base.py", line 39, in load_middleware
mw_instance = middleware(handler)
TypeError: object() takes no parameters

According to StackExchange and other sites, the cause of this error is the deprecation of certain things from 1.x to 2.x and the solution is the MiddlewareMixin which should be used like this: class FOOMiddleware(MiddlewareMixin): ...

My MIDDLEWARE settings are:

MIDDLEWARE = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'reversion.middleware.RevisionMiddleware',
# Uncomment the next line for simple clickjacking protection:
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
'users.middleware.TimezoneMiddleware')

But I don't have any classes and also, the get_wsgi_application() function should still work, as far as I know.
How should I solve this?

Peursem answered 27/2, 2018 at 7:30 Comment(7)
is your code tabbed right?? it looks like an error with tabs and spacingFoetor
It should be tabbed right, but the tabs were messed up when I pasted the code into SE...Peursem
What is your MIDDLEWARE setting?Queenstown
updated the postPeursem
I'm also facing the same. @Peursem can you share how did you fix the problem?Rosalie
@Rosalie Have you fixed the issue? I could see the same issue while migrationg django 1.10 to 3.2.Paternalism
@RameshPasham I don't exactly remember, but it has to do with the middleware settings and middleware versionsRosalie
S
0

Maybe it's because of the debug_toolbar, as the only one third-party library. Anyway , try to update django_debug_toolbar to lastest version.

Shaver answered 21/7, 2020 at 6:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.