Use with aiohttp?
jordemort opened this issue · comments
Hi, is there any guidance or example of how to use a2wsgi with aiohttp? I have an app written using aiohttp, and I would like to run it under a WSGI server.
I've tried breaking things down to be as simple as possible but I can't seem to figure out how to make it work. Here is my test code:
from aiohttp import web
from a2wsgi import ASGIMiddleware
from asgiref.compatibility import guarantee_single_callable
from wsgiref.simple_server import make_server
async def hello(request):
return web.Response(text="Hello, world")
app = web.Application()
app.add_routes([web.get('/', hello)])
#wsgi = ASGIMiddleware(app)
wsgi = ASGIMiddleware(guarantee_single_callable(app))
with make_server('', 8000, wsgi) as httpd:
httpd.serve_forever()
With this, requests just return a 500 error with the message "Server got itself in trouble" - I've tried adding loggers and setting debug=True on the application, but I am unable to get a backtrace out of it to see what exactly is going wrong.
If I remove guarantee_single_callable
, then I get a traceback:
Traceback (most recent call last):
File "/usr/lib/python3.8/wsgiref/handlers.py", line 138, in run
self.finish_response()
File "/usr/lib/python3.8/wsgiref/handlers.py", line 183, in finish_response
for data in self.result:
File "/home/jordan/Work/kdy-client/venv/lib/python3.8/site-packages/a2wsgi/asgi.py", line 157, in __call__
self.app(build_scope(environ), self.asgi_receive, self.asgi_send)
TypeError: __call__() takes 1 positional argument but 4 were given
I dug around on the internet but the only examples I could find using ASGIMiddleware all use it with FastAPI.
Can you give me any hints on how to make this work, or how to debug it so I can figure out why it is not working?
Actually, I've gotten things twisted, it doesn't appear that aiohttp
is actually an ASGI framework. I'm having similar problems with Blacksheep, though, and that definitely is an ASGI framework, I'll open another issue.