[Django] #31984: Uvicorn + Django: TypeError: object HttpResponse can't be used in 'await' expression

336 views
Skip to first unread message

Django

unread,
Sep 5, 2020, 6:49:51 PM9/5/20
to django-...@googlegroups.com
#31984: Uvicorn + Django: TypeError: object HttpResponse can't be used in 'await'
expression
-----------------------------------------+-------------------------------
Reporter: aaronn | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 3.1
Severity: Normal | Keywords: asgi, uvicorn
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+-------------------------------
It seems like running Django with an asgi server like uvicorn in 3.1
causes `TypeError: object HttpResponse can't be used in 'await'
expression` to be raised. Runserver works fine, as does gunicorn + wsgi.
This is happening across two different projects for me.

```
[2020-09-05 15:34:28 -0700] [93779] [INFO] Booting worker with pid: 93779
[2020-09-05 15:34:28 -0700] [93780] [INFO] Booting worker with pid: 93780
[2020-09-05 15:34:28 -0700] [93781] [INFO] Booting worker with pid: 93781
[2020-09-05 15:34:28 -0700] [93782] [INFO] Booting worker with pid: 93782
[2020-09-05 22:34:30 +0000] [93780] [INFO] Started server process [93780]
[2020-09-05 22:34:30 +0000] [93781] [INFO] Started server process [93781]
[2020-09-05 22:34:30 +0000] [93782] [INFO] Started server process [93782]
[2020-09-05 22:34:30 +0000] [93779] [INFO] Started server process [93779]
Internal Server Error: /users/self/
Traceback (most recent call last):
File "/Users/james/Github/oregano-server/.venv/lib/python3.7/site-
packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/Users/james/Github/oregano-server/.venv/lib/python3.7/site-
packages/django/utils/deprecation.py", line 116, in __call__
response = self.process_response(request, response)
File "/Users/james/Github/oregano-server/.venv/lib/python3.7/site-
packages/django/middleware/clickjacking.py", line 26, in process_response
if response.get('X-Frame-Options') is not None:
AttributeError: 'coroutine' object has no attribute 'get'
2020-09-05 22:35:03,901 ERROR Internal Server Error: /users/self/
Traceback (most recent call last):
File "/Users/james/Github/oregano-server/.venv/lib/python3.7/site-
packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/Users/james/Github/oregano-server/.venv/lib/python3.7/site-
packages/django/utils/deprecation.py", line 116, in __call__
response = self.process_response(request, response)
File "/Users/james/Github/oregano-server/.venv/lib/python3.7/site-
packages/django/middleware/clickjacking.py", line 26, in process_response
if response.get('X-Frame-Options') is not None:
AttributeError: 'coroutine' object has no attribute 'get'
Internal Server Error: /users/self/
Traceback (most recent call last):
File "/Users/james/Github/oregano-server/.venv/lib/python3.7/site-
packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/Users/james/Github/oregano-server/.venv/lib/python3.7/site-
packages/whitenoise/middleware.py", line 59, in __call__
response = self.get_response(request)
File "/Users/james/Github/oregano-server/.venv/lib/python3.7/site-
packages/asgiref/sync.py", line 139, in __call__
return call_result.result()
File
"/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/_base.py",
line 428, in result
return self.__get_result()
File
"/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/_base.py",
line 384, in __get_result
raise self._exception
File "/Users/james/Github/oregano-server/.venv/lib/python3.7/site-
packages/asgiref/sync.py", line 204, in main_wrap
result = await self.awaitable(*args, **kwargs)
TypeError: object HttpResponse can't be used in 'await' expression
2020-09-05 22:35:03,982 ERROR Internal Server Error: /users/self/
Traceback (most recent call last):
File "/Users/james/Github/oregano-server/.venv/lib/python3.7/site-
packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/Users/james/Github/oregano-server/.venv/lib/python3.7/site-
packages/whitenoise/middleware.py", line 59, in __call__
response = self.get_response(request)
File "/Users/james/Github/oregano-server/.venv/lib/python3.7/site-
packages/asgiref/sync.py", line 139, in __call__
return call_result.result()
File
"/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/_base.py",
line 428, in result
return self.__get_result()
File
"/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/_base.py",
line 384, in __get_result
raise self._exception
File "/Users/james/Github/oregano-server/.venv/lib/python3.7/site-
packages/asgiref/sync.py", line 204, in main_wrap
result = await self.awaitable(*args, **kwargs)
TypeError: object HttpResponse can't be used in 'await' expression
```

--
Ticket URL: <https://code.djangoproject.com/ticket/31984>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 5, 2020, 6:50:20 PM9/5/20
to django-...@googlegroups.com
#31984: Uvicorn + Django: TypeError: object HttpResponse can't be used in 'await'
expression
-------------------------------+--------------------------------------

Reporter: aaronn | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 3.1
Severity: Normal | Resolution:

Keywords: asgi, uvicorn | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Description changed by aaronn:

Old description:

New description:

}}}

--

--
Ticket URL: <https://code.djangoproject.com/ticket/31984#comment:1>

Django

unread,
Sep 5, 2020, 6:50:55 PM9/5/20
to django-...@googlegroups.com
#31984: Uvicorn + Django: TypeError: object HttpResponse can't be used in 'await'
expression
-------------------------------+--------------------------------------

Reporter: aaronn | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 3.1
Severity: Normal | Resolution:

Keywords: asgi, uvicorn | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Description changed by aaronn:

Old description:

> It seems like running Django with an asgi server like uvicorn in 3.1

New description:

packages/asgiref/sync.py", line 139, in __call__
return call_result.result()
File
"/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/_base.py",
line 428, in result
return self.__get_result()
File
"/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/_base.py",
line 384, in __get_result
raise self._exception
File "/Users/james/Github/oregano-server/.venv/lib/python3.7/site-
packages/asgiref/sync.py", line 204, in main_wrap
result = await self.awaitable(*args, **kwargs)
TypeError: object HttpResponse can't be used in 'await' expression
2020-09-05 22:35:03,982 ERROR Internal Server Error: /users/self/
Traceback (most recent call last):
File "/Users/james/Github/oregano-server/.venv/lib/python3.7/site-
packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/Users/james/Github/oregano-server/.venv/lib/python3.7/site-

packages/asgiref/sync.py", line 139, in __call__
return call_result.result()
File
"/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/_base.py",
line 428, in result
return self.__get_result()
File
"/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/_base.py",
line 384, in __get_result
raise self._exception
File "/Users/james/Github/oregano-server/.venv/lib/python3.7/site-
packages/asgiref/sync.py", line 204, in main_wrap
result = await self.awaitable(*args, **kwargs)
TypeError: object HttpResponse can't be used in 'await' expression

}}}

--

--
Ticket URL: <https://code.djangoproject.com/ticket/31984#comment:2>

Django

unread,
Sep 6, 2020, 3:04:04 AM9/6/20
to django-...@googlegroups.com
#31984: TypeError: object HttpResponse can't be used in 'await' expression.
-------------------------------+--------------------------------------
Reporter: Aaron Ng | Owner: nobody
Type: Bug | Status: closed
Component: HTTP handling | Version: 3.1
Severity: Normal | Resolution: needsinfo

Keywords: asgi, uvicorn | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by felixxm):

* status: new => closed
* resolution: => needsinfo
* component: Uncategorized => HTTP handling


Comment:

I'm not able to reproduce this issue with a sample project and builtin
middlewares. It looks that you're using a middleware which doesn't detect
properly an async response. Can you provide a same project that reproduces
this issue?

--
Ticket URL: <https://code.djangoproject.com/ticket/31984#comment:3>

Reply all
Reply to author
Forward
0 new messages