AttributeError: 'coroutine' object has no attribute 'has_header' (Django 3.1)
See original GitHub issueHi,
I cannot use this middleware with an ASGI server. I tried with Daphne and Uvicorn, they both give me the following error:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/usr/local/lib/python3.7/site-packages/django/utils/deprecation.py", line 116, in __call__
response = self.process_response(request, response)
File "/usr/local/lib/python3.7/site-packages/corsheaders/middleware.py", line 111, in process_response
patch_vary_headers(response, ["Origin"])
File "/usr/local/lib/python3.7/site-packages/django/utils/cache.py", line 286, in patch_vary_headers
if response.has_header('Vary'):
AttributeError: 'coroutine' object has no attribute 'has_header'
Steps to reproduce:
pip install django==3.1 daphne
django-admin startproject example
- Add
corsheaders
inINSTALLED_APPS
- Add
corsheaders.middleware.CorsMiddleware
inMIDDLEWARE
daphne example.asgi:application
curl 127.0.0.1:8000
(in another terminal)
Best regards, Benoit
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
How to correct " 'coroutine' object has no attribute 'data'" Error ...
I keep getting an error that I cannot solve and for which I do not understand the reason. "'coroutine' object has no attribute...
Read more >'coroutine' object has no attribute 'has_header' (Django 3.1)
AttributeError : 'coroutine' object has no attribute 'has_header' (Django 3.1)
Read more >AttributeError: 'coroutine' object has no attribute 'error' - Reddit
I have .error events for my commands but they do not seem to work and show AttributeError: 'coroutine' object has no attribute 'error'....
Read more >Mastering Telethon — Telethon 1.7.7 documentation
AttributeError : 'coroutine' object has no attribute 'id'. You probably had a previous version, upgraded, and expected everything to work.
Read more >sys:1: runtimewarning: coroutine 'main' was never awaited
Note that simply calling a coroutine will not schedule it to be executed ... GUI raised exception: AttributeError("'SilentTaskGroup' object has no attribute ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
After investigating the issue, I found out that Django seems to pass a coroutine instead of the response to the first middleware’s
process_response
on the list, which usually ends up being thiscorsheaders
. All other middlewares receive a response object. I’m not sure if this is by design or a bug in Django. Creating a dummy middleware that does nothing and placing it in front ofcorsheaders
seems to “solve” the issue.@xtof-osd This is more of a workaround: https://docs.djangoproject.com/en/3.1/topics/async/#async-views
but if someone’s in a pinch this can be done in(see my other comment below)settings.py
right now: