Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CorsMiddleware is not working in Django 1.10 #102

Closed
adrysn opened this issue Aug 2, 2016 · 14 comments
Closed

CorsMiddleware is not working in Django 1.10 #102

adrysn opened this issue Aug 2, 2016 · 14 comments

Comments

@adrysn
Copy link

adrysn commented Aug 2, 2016

CorsMiddleware is not working with Django 1.10. If it is inserted into the list of middlewares in settings file, an error occurs such as below.

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x110eaa158>
Traceback (most recent call last):
  File "/Users/adrysn/.pyenv/versions/neumann35/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/Users/adrysn/.pyenv/versions/neumann35/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 142, in inner_run
    handler = self.get_handler(*args, **options)
  File "/Users/adrysn/.pyenv/versions/neumann35/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/runserver.py", line 27, in get_handler
    handler = super(Command, self).get_handler(*args, **options)
  File "/Users/adrysn/.pyenv/versions/neumann35/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 64, in get_handler
    return get_internal_wsgi_application()
  File "/Users/adrysn/.pyenv/versions/neumann35/lib/python3.5/site-packages/django/core/servers/basehttp.py", line 49, in get_internal_wsgi_application
    return import_string(app_path)
  File "/Users/adrysn/.pyenv/versions/neumann35/lib/python3.5/site-packages/django/utils/module_loading.py", line 20, in import_string
    module = import_module(module_path)
  File "/Users/adrysn/.pyenv/versions/3.5.0/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 662, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/Users/adrysn/lablup/neumann/neumann/wsgi.py", line 17, in <module>
    application = get_wsgi_application()
  File "/Users/adrysn/.pyenv/versions/neumann35/lib/python3.5/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
    return WSGIHandler()
  File "/Users/adrysn/.pyenv/versions/neumann35/lib/python3.5/site-packages/django/core/handlers/wsgi.py", line 153, in __init__
    self.load_middleware()
  File "/Users/adrysn/.pyenv/versions/neumann35/lib/python3.5/site-packages/django/core/handlers/base.py", line 82, in load_middleware
    mw_instance = middleware(handler)
TypeError: object() takes no parameters

This error is probably due to the changed style of middleware introduced in Django 1.10:
https://docs.djangoproject.com/en/1.10/topics/http/middleware/.

The middleware class should be updated to comply with the new style.

For the moment, one can replace object to MiddlewareMixin to enable the middleware.

from django.utils.deprecation import MiddlewareMixin

class CorsPostCsrfMiddleware(MiddlewareMixin):
...

class CorsMiddleware(MiddlewareMixin):
...
@edmorley
Copy link
Contributor

edmorley commented Aug 2, 2016

I made some initial progress on Django 1.10 support in this project's more maintained fork:
zestedesavoir#19

If someone wants to finish it up before I get a chance to double back and do so myself, feel free :-)

@adrysn
Copy link
Author

adrysn commented Aug 2, 2016

Thanks. I didn't know there's more active forks. Then, I close this issue.

@adrysn adrysn closed this as completed Aug 2, 2016
@edmorley
Copy link
Contributor

edmorley commented Aug 2, 2016

I'd perhaps leave this open, to make it clearer to those finding this project, that it doesn't support Django 1.10?

@adrysn
Copy link
Author

adrysn commented Aug 2, 2016

Sure, no problem!

@adrysn adrysn reopened this Aug 2, 2016
@fengsi
Copy link

fengsi commented Aug 5, 2016

@adrysn did you mean this project is not maintained anymore?

@Austyns
Copy link

Austyns commented Aug 9, 2016

@adrysn Thanks alot, your post have saved me after hours of debugging and surfing the internet for solutions on the CorsMiddleware issue with django 1.10

@fotorius
Copy link

Apparently django-cors-headers is no longer maintained, django-cors-middleware is a good alternative:
https://pypi.python.org/pypi/django-cors-middleware/

@arthur-s
Copy link

arthur-s commented Sep 2, 2016

@devalfrz, thanks

@akki
Copy link

akki commented Sep 27, 2016

Can we please mention this in the README of this project. After spending so much time with this repo, there is no way to know that django-cors-middleware is being maintained and we are stuck with the TypeError: object() takes no parameters error.

@adamchainz
Copy link
Owner

I've emailed @ottoyiu asking to be added as a maintainer but no reply

@adamchainz
Copy link
Owner

Now I've been added as maintainer (see #110) I've merged Django 1.10 support, and deployed to PyPI at version 1.2.0. Enjoy.

@akki
Copy link

akki commented Oct 4, 2016

Should we consider closing this issue then? (Haven't checked it myself though).

@adamchainz
Copy link
Owner

This issue is closed 😄 . We are still upgrading to 1.10 at work but django-cors-headers isn't causing any of the problems there, no obvious failures in our test suite.

@akki
Copy link

akki commented Oct 4, 2016

Ahh, didn't notice that. Sorry! 😝
Thanks for the great job, @adamchainz 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants