Last active
August 28, 2020 16:35
-
-
Save alex-oleshkevich/80dab249a8fef9e47f1f82bed74d2c34 to your computer and use it in GitHub Desktop.
[medium] django 3 websockets. middleware
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.urls import resolve | |
from .connection import WebSocket | |
def websockets(app): | |
async def asgi(scope, receive, send): | |
if scope["type"] == "websocket": | |
match = resolve(scope["raw_path"]) | |
await match.func(WebSocket(scope, receive, send), *match.args, **match.kwargs) | |
return | |
await app(scope, receive, send) | |
return asgi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ERROR: Exception in ASGI application Traceback (most recent call last): File "/usr/src/app/env/lib/python3.7/site-packages/uvicorn/protocols/http/httptools_impl.py", line 390, in run_asgi result = await app(self.scope, self.receive, self.send) File "/usr/src/app/env/lib/python3.7/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__ return await self.app(scope, receive, send) File "./shop/middleware.py", line 21, in asgi await app(scope, receive, send) File "/usr/src/app/env/lib/python3.7/site-packages/django/core/handlers/asgi.py", line 161, in __call__ response = await self.get_response_async(request) File "/usr/src/app/env/lib/python3.7/site-packages/django/core/handlers/base.py", line 148, in get_response_async response = await self._middleware_chain(request) TypeError: object HttpResponse can't be used in 'await' expression Exception in ASGI application Traceback (most recent call last): File "/usr/src/app/env/lib/python3.7/site-packages/uvicorn/protocols/http/httptools_impl.py", line 390, in run_asgi result = await app(self.scope, self.receive, self.send) File "/usr/src/app/env/lib/python3.7/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__ return await self.app(scope, receive, send) File "./shop/middleware.py", line 21, in asgi await app(scope, receive, send) File "/usr/src/app/env/lib/python3.7/site-packages/django/core/handlers/asgi.py", line 161, in __call__ response = await self.get_response_async(request) File "/usr/src/app/env/lib/python3.7/site-packages/django/core/handlers/base.py", line 148, in get_response_async response = await self._middleware_chain(request) TypeError: object HttpResponse can't be used in 'await' expression INFO: - "GET /favicon.ico HTTP/1.0" 500 Internal Server Error