Some issues were surfaced when testing on testbed:
It appears that we're only a WSGI app, not an ASGI app. We need to tell uvicorn this fact, or it will error out when handling a request:
sdx-controller-1 | ERROR: Exception in ASGI application
sdx-controller-1 | Traceback (most recent call last):
sdx-controller-1 | File "/usr/local/lib/python3.9/site-packages/uvicorn/protocols/http/h11_impl.py", line 404, in run_asgi
sdx-controller-1 | result = await app( # type: ignore[func-returns-value]
sdx-controller-1 | File "/usr/local/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in __call__
sdx-controller-1 | return await self.app(scope, receive, send)
sdx-controller-1 | File "/usr/local/lib/python3.9/site-packages/uvicorn/middleware/asgi2.py", line 16, in __call__
sdx-controller-1 | instance = self.app(scope)
sdx-controller-1 | TypeError: __call__() missing 1 required positional argument: 'start_response'
There are two ways to handle this. We can either pass an --interface wsgi argument to uvicorn, or use the asgiref.WsgiToAsgi adapter (as described here). I like the latter option, because that way we can switch to other ASGI servers also, if we need to.
The second problem is that we need to bind to 0.0.0.0:8080 (and not localhost:8080) so that the port can be exposed to the world.
Some issues were surfaced when testing on testbed:
It appears that we're only a WSGI app, not an ASGI app. We need to tell uvicorn this fact, or it will error out when handling a request:
There are two ways to handle this. We can either pass an
--interface wsgi
argument to uvicorn, or use theasgiref.WsgiToAsgi
adapter (as described here). I like the latter option, because that way we can switch to other ASGI servers also, if we need to.The second problem is that we need to bind to
0.0.0.0:8080
(and notlocalhost:8080
) so that the port can be exposed to the world.