run_async.py example not working as expected
schef opened this issue · comments
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
When i run the async example i got the following output:
[2023-06-16 09:12:04 +0200] [5987] [INFO]
┌─────────────────────────────────────────────────────────────────────────────┐
│ Sanic v23.3.0 │
│ Goin' Fast @ http://0.0.0.0:8000 │
├───────────────────────┬─────────────────────────────────────────────────────┤
│ │ mode: production, single worker │
│ ▄███ █████ ██ │ server: sanic, HTTP/1.1 │
│ ██ │ python: 3.11.3 │
│ ▀███████ ███▄ │ platform: Linux-6.3.7-arch1-1-x86_64-with-glibc2.37 │
│ ██ │ packages: sanic-routing==22.8.0, sanic-ext==23.3.0 │
│ ████ ████████▀ │ │
│ │ │
│ Build Fast. Run Fast. │ │
└───────────────────────┴─────────────────────────────────────────────────────┘
[2023-06-16 09:12:04 +0200] [5987] [WARNING] Sanic is running in PRODUCTION mode. Consider using '--debug' or '--dev' while actively developing your application.
[2023-06-16 09:12:04 +0200] [5987] [INFO] Sanic Extensions:
[2023-06-16 09:12:04 +0200] [5987] [INFO] > injection [0 dependencies; 0 constants]
[2023-06-16 09:12:04 +0200] [5987] [INFO] > openapi [http://<unknown>/docs]
[2023-06-16 09:12:04 +0200] [5987] [INFO] > http
The strange thing is that the openapi has the <unknown>
part. When i try to call curl localhost:8000/ -X GET
i get the result {"answer":"42"}
but the following output from the sanic log is strange:
[2023-06-16 09:16:06 +0200] [6242] [ERROR] Exception occurred in one of response middleware handlers
Traceback (most recent call last):
File "/home/schef/.local/lib/python3.11/site-packages/sanic/request/types.py", line 318, in respond
response = await self.app._run_response_middleware(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "_run_response_middleware", line 17, in _run_response_middleware
from asyncio.futures import Future
^^^^^^^^^^^
File "/home/schef/.local/lib/python3.11/site-packages/sanic_ext/extensions/http/cors.py", line 54, in _add_cors_headers
_add_origin_header(request, response)
File "/home/schef/.local/lib/python3.11/site-packages/sanic_ext/extensions/http/cors.py", line 160, in _add_origin_header
allow_origins = _get_from_cors_ctx(
^^^^^^^^^^^^^^^^^^^
File "/home/schef/.local/lib/python3.11/site-packages/sanic_ext/extensions/http/cors.py", line 151, in _get_from_cors_ctx
value = getattr(request.route.ctx._cors, key, default)
^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'types.SimpleNamespace' object has no attribute '_cors'
Is there a solution for this issue?
Code snippet
No response
Expected Behavior
No response
How do you run Sanic?
As a script (app.run
or Sanic.serve
)
Operating System
Arch Linux
Sanic Version
Sanic 23.3.0; Routing 22.8.0
Additional context
I want to be able use the server using asyncio.
You probably have Sanic Extensions installed, which is not compatible with a low-level form of running Sanic.
What is the motivation for running this way?