Uvicorn: TypeError: __call__() missing 1 required positional argument: 'start_response' ?

Created on 9 Nov 2019  Â·  2Comments  Â·  Source: encode/uvicorn

Hello, I recently decided to integrate Django Channel into one of my projects. I mainly use Django cookie cutter for my projects. After reading several documents, I could understand that the easiest integration was the use of uvicorn gunicorn, so I created my Routing file, my ASGI file, I created my workers etc... and everything works well locally (with the manage.py runserver command) now I try to use unicorn with uvicorn in production. So I added -k uvicorn.workers.UvicornWorker to my command. Here is the complete command:

/usr/local/bin/gunicorn config.wsgi --bind 0.0.0.0.:5000 --chdir=/app -k uvicorn.workers.UvicornWorker
but I'm getting a strange error I haven't found an answer to this error there:

django_1        | Traceback (most recent call last):
django_1        |   File "/usr/local/lib/python3.7/site-packages/uvicorn/protocols/http/httptools_impl.py", line 376, in run_asgi
django_1        |     result = await app(self.scope, self.receive, self.send)
django_1        |   File "/usr/local/lib/python3.7/site-packages/uvicorn/middleware/asgi2.py", line 6, in __call__
django_1        |     instance = self.app(scope)
django_1        | TypeError: __call__() missing 1 required positional argument: 'start_response'
django_1        | [2019-11-09 18:16:04 +0000] [36] [INFO] ('172.23.0.9', 50440) - "GET / HTTP/1.1" 500
django_1        | [2019-11-09 18:16:05 +0000] [36] [ERROR] Exception in ASGI application
django_1        | Traceback (most recent call last):
django_1        |   File "/usr/local/lib/python3.7/site-packages/uvicorn/protocols/http/httptools_impl.py", line 376, in run_asgi
django_1        |     result = await app(self.scope, self.receive, self.send)
django_1        |   File "/usr/local/lib/python3.7/site-packages/uvicorn/middleware/asgi2.py", line 6, in __call__
django_1        |     instance = self.app(scope)
django_1        | TypeError: __call__() missing 1 required positional argument: 'start_response'
django_1        | [2019-11-09 18:16:05 +0000] [36] [INFO] ('172.23.0.9', 50444) - "GET /favicon.ico HTTP/1.1" 500
django_1        | [2019-11-09 18:16:10 +0000] [36] [ERROR] Exception in ASGI application
django_1        | Traceback (most recent call last):
django_1        |   File "/usr/local/lib/python3.7/site-packages/uvicorn/protocols/http/httptools_impl.py", line 376, in run_asgi
django_1        |     result = await app(self.scope, self.receive, self.send)
django_1        |   File "/usr/local/lib/python3.7/site-packages/uvicorn/middleware/asgi2.py", line 6, in __call__
django_1        |     instance = self.app(scope)
django_1        | TypeError: __call__() missing 1 required positional argument: 'start_response'
django_1        | [2019-11-09 18:16:10 +0000] [36] [INFO] ('172.23.0.9', 50452) - "GET / HTTP/1.1" 500
django_1        | [2019-11-09 18:16:10 +0000] [36] [ERROR] Exception in ASGI application
django_1        | Traceback (most recent call last):
django_1        |   File "/usr/local/lib/python3.7/site-packages/uvicorn/protocols/http/httptools_impl.py", line 376, in run_asgi
django_1        |     result = await app(self.scope, self.receive, self.send)
django_1        |   File "/usr/local/lib/python3.7/site-packages/uvicorn/middleware/asgi2.py", line 6, in __call__
django_1        |     instance = self.app(scope)
django_1        | TypeError: __call__() missing 1 required positional argument: 'start_response'
django_1        | [2019-11-09 18:16:10 +0000] [36] [INFO] ('172.23.0.9', 50456) - "GET /favicon.ico HTTP/1.1" 500

if it would be possible to guide me to find the most appropriate solution. Thank you in advance

Most helpful comment

Uvicorn should be pointed at an ASGI app. It looks like you’re pointing it at a WSGI app “config.wsgi”.

I think Django Channels “Deploying with Uvicorn” docs should be able to guide you here.

All 2 comments

Uvicorn should be pointed at an ASGI app. It looks like you’re pointing it at a WSGI app “config.wsgi”.

I think Django Channels “Deploying with Uvicorn” docs should be able to guide you here.

Thank you for your answer, it works perfectly now, I replaced config.wsgi by my config.asgi.
I didn't find help on django channels it is now just indicated:

Alternative Web Servers
There are also alternative ASGI servers that you can use for serving Channels.

To some degree ASGI web servers should be interchangeable, they should all have the same basic functionality in terms of serving HTTP and WebSocket requests.

Aspects where servers may differ are in their configuration and defaults, performance characteristics, support for resource limiting, differing protocol and socket support, and approaches to process management.

You can see more alternative servers, such as Uvicorn, in the ASGI implementations documentation.

Thanks again for your help:)

Was this page helpful?
0 / 5 - 0 ratings