8

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.

12
  • 1
    can you add the file /app/wsgi.py ? Commented Aug 31, 2018 at 6:05
  • 1
    update the question with your INSTALLED_APPS please; and your MIDDLEWARE list is not in the right order. 'django.middleware.security.SecurityMiddleware', should be above 'whitenoise.middleware.WhiteNoiseMiddleware', Commented Sep 2, 2018 at 5:03
  • 1
    I would suggest adding a breakpoint (or print statement) before line 36 in django/utils/deprecation.py to inspect the variable middleware_path. Commented Sep 3, 2018 at 12:42
  • 1
    Have you checked your versions of middlewares? It looks like whitenoise would be the culprit. Did you pip install --upgrade it to a version that is compatible with django 2.1? Commented Sep 3, 2018 at 13:10
  • 1
    As is mentioned above, I would try to figure out which middleware is causing the problem, either with a breakpoint, or by adding a print statement just above the line that causes problem. Commented Sep 3, 2018 at 17:36

2 Answers 2

9
+100

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
    ...
    
Sign up to request clarification or add additional context in comments.

2 Comments

inspecting settings doesn't give me any different result. I will try putting breakpoints in Django source and find out which middleware causes the problem and I think that is the only way to a solution here after.
@Ram Where was the problem?
4

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

13 Comments

Now I'm getting the same error starting at "application = CustomSentry(get_wsgi_application())"
I guess it's something to deal with the get_wsgi_application(), you must be able to reproduce the error if you just create a wsgi.py in a project with the same code as above and try running it with the mentioned dependencies (celery 4.2.1, raven version : 6.9.0, django version : 2.1 & python 3.5)
Can you add the whitenoise version ?
Did you tried to run the server by commenting out whitenoise middleware ?
I reproduced the error by adding a custom middleware class as mentioned in my references-1. Is there any way you could share the project?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.