Issue in django channels ASGI server - (TypeError: object HttpResponse can't be used in 'await' expression)

We’re integrating django channels to our existing django application built with wsgi server, but when integrating channels to our application documentation suggests to use daphne but when we hit any other API’s it is thowring error like this

Internal Server Error: /dashboard/summary/
Traceback (most recent call last):
File “D:\Backend\Edge-Backend\env\Lib\site-packages\django\core\handlers\exception.py”, line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File “D:\Backend\Edge-Backend\env\Lib\site-packages\django\utils\deprecation.py”, line 136, in call
response = self.process_response(request, response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “D:\Backend\Edge-Backend\env\Lib\site-packages\django\middleware\clickjacking.py”, line 27, in process_response
if response.get(“X-Frame-Options”) is not None:
^^^^^^^^^^^^
AttributeError: ‘coroutine’ object has no attribute ‘get’
2025-02-13 08:46:29,417 Internal Server Error: /dashboard/part_summary/
Traceback (most recent call last):
File “D:\Backend\Edge-Backend\env\Lib\site-packages\django\core\handlers\exception.py”, line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File “D:\Backend\Edge-Backend\env\Lib\site-packages\django\utils\deprecation.py”, line 136, in call
response = self.process_response(request, response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “D:\Backend\Edge-Backend\env\Lib\site-packages\django\middleware\clickjacking.py”, line 27, in process_response
if response.get(“X-Frame-Options”) is not None:
^^^^^^^^^^^^
AttributeError: ‘coroutine’ object has no attribute ‘get’
2025-02-13 08:46:29,536 Exception inside application: object HttpResponse can’t be used in ‘await’ expression
Traceback (most recent call last):
File “D:\Backend\Edge-Backend\env\Lib\site-packages\django\contrib\staticfiles\handlers.py”, line 101, in call
return await self.application(scope, receive, send)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “D:\Backend\Edge-Backend\env\Lib\site-packages\channels\routing.py”, line 48, in call
return await application(scope, receive, send)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “D:\Backend\Edge-Backend\env\Lib\site-packages\django\core\handlers\asgi.py”, line 160, in call
await self.handle(scope, receive, send)
File “D:\Backend\Edge-Backend\env\Lib\site-packages\django\core\handlers\asgi.py”, line 183, in handle
response = await self.get_response_async(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “D:\Backend\Edge-Backend\env\Lib\site-packages\django\core\handlers\base.py”, line 162, in get_response_async
response = await self._middleware_chain(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: object HttpResponse can’t be used in ‘await’ expression
HTTP GET /dashboard/part_summary/ 500 [0.18, 127.0.0.1:61794]
2025-02-13 08:46:29,540 HTTP GET /dashboard/part_summary/ 500 [0.18, 127.0.0.1:61794]

@KenWhitesell could you help me on this ?

First, please do not tag any individual requesting assistance. (Personally, I don’t mind it all that much, because as a moderator, one of my duties is to read every message coming in. But in the general case, it’s not considered appropriate here.)

Second, from the traceback, I’m going to assume you’re trying to do this in Windows. I’m going to warn you about this - people generally have problems getting Daphne to work well in Windows. (See Django Channels with Redis slow intialization for one such example.) Now, those types of issues have nothing to do with what you’re facing here, but I’m just letting you know this in advance. (My understanding is that there is a way to work around these kinds of problems, but I’ve never found a definitive statement how - and since I abandoned Windows as a target platform many years ago, I’ve never spent the time trying to find an answer myself.)

Are you looking to run your Django code asynchronously? Or just the Channels websocket consumers?

At a minimum, to get started with this, we’ll need to see:

  • The command line being used to run your project.
  • These settings from your settings.py file:
    • INSTALLED_APPS
    • WSGI_APPLICATION
    • ASGI_APPLICATION
    • CHANNEL_LAYERS

Please post the contents of your asgi.py, and routing.py files. (This may just be the starting point. There might be more files needed to be seen.)

This is almost certainly an incompatible middleware. (A coroutine to be awaited is expected here, rather than a response object directly.)

You need to go through your dependencies and make sure any middleware correctly handle async integration

Thank you for your responses mates, I just started my asgi server in another port and this worked.