I'm porting a django application from 1.x to 2.1 and got stuck with the error that says "TypeError: object() takes no parameters". I'm trying to solve the problem for quite a while but not even got a clue even after days of debugging and searching online
Installed apps:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.github',
'timezone_field',
'axes',
'humans',
'boxes',
'pages',
]
Middleware settings:
MIDDLEWARE = [
'whitenoise.middleware.WhiteNoiseMiddleware',
'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',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
]
There are no problems with the indentation,
celery version : 4.2.1
raven version : 6.9.0
django version : 2.1
Here is my wsgi.py
import os
from raven.contrib.django.raven_compat.middleware.wsgi import Sentry
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
application=Sentry(get_wsgi_application())
Here is an excerpt from the error log
File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/app/wsgi.py", line 16, in <module>
application=Sentry(get_wsgi_application())
File "/usr/local/lib/python3.5/dist-packages/django/core/wsgi.py", line 13, in get_wsgi_application
return WSGIHandler()
File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/wsgi.py", line 136, in __init__
self.load_middleware()
File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 36, in load_middleware
mw_instance = middleware(handler)
TypeError: object() takes no parameters
Error after using CustomSentry :
in <module>
application = CustomSentry(get_wsgi_application())
File "/usr/local/lib/python3.5/dist-packages/django/core/wsgi.py", line 13, in get_wsgi_application
return WSGIHandler()
File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/wsgi.py", line 136, in __init__
self.load_middleware()
File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 36, in load_middleware
mw_instance = middleware(handler)
TypeError: object() takes no parameters
I tried to catch the exceptions using ExceptionMiddleware, now I'm getting the following error:
application = CustomSentry(get_wsgi_application())
File "/usr/local/lib/python3.5/dist-packages/django/utils/deprecation.py", line 85, in __init__
super().__init__()
TypeError: __init__() missing 1 required positional argument: 'application'
Any help would be appreciated.
We can declare a __init__ method inside a class in Python using the following syntax: class class_name(): def __init__(self): # Required initialisation for data members # Class methods … …
The Python "TypeError: Class() takes no arguments" occurs when we forget to define an __init__() method in a class but provide arguments when instantiating it. To solve the error, make sure to define the __init__() (two underscores on each side) method in the class.
Middleware is a framework of hooks into Django's request/response processing. It's a light, low-level “plugin” system for globally altering Django's input or output. Each middleware component is responsible for doing some specific function.
The error indicates that you have an old-style middleware in your middleware list. Old-style middlewares did not receive an argument upon instantiation, while new-style middlewares receive a handler.
Now, according to your settings, the only non-Django middleware is whitenoise, but you say that the error persists even after commenting that out.
Here are some suggestion to help you figure out what's going on:
As I have commented, add a breakpoint or print statement to the Django source to figure out which middleware causes the issue.
Make sure that the settings file you are editing is the one that is actually used.
Use the Python shell to inspect the actual value of the MIDDLEWARE
setting:
$ python manage.py shell
>>> from django.conf import settings
>>> settings.MIDDLEWARE
...
try this in you /app/wsgi.py
module,
import os
from raven.contrib.django.raven_compat.middleware.wsgi import Sentry
from django.core.wsgi import get_wsgi_application
from django.utils.deprecation import MiddlewareMixin
class CustomSentry(MiddlewareMixin, Sentry):
pass
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
application = CustomSentry(get_wsgi_application())
References
1. object() takes no parameters in django 1.10
2. Django exception middleware: TypeError: object() takes no parameters
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With