TypeError: handle_request() takes 2 positional arguments but 3 were given
what is wrong with my code
import asyncio
from aiohttp_wsgi import wsgi
from aiohttp import web
async def http_server_handler(request):
headers = {}
headers['Content-Type'] = 'text/html'
response = web.StreamResponse(
status=200,
reason='OK',
headers=headers,
)
await response.prepare(request)#没有这行 RuntimeError: Cannot call write() before prepare()
data=b'2333333'
await response.write(data) #AssertionError: data argument must be byte-ish
await response.write_eof()
return response
app = web.Application()
app.router.add_route('*', '/', http_server_handler)
# web.run_app(app, host='0.0.0.0', port=8080)
# loop=asyncio.get_event_loop()
from concurrent.futures import ThreadPoolExecutor
executor = ThreadPoolExecutor(4) # > 1
application=wsgi.WSGIHandler(
app,
loop=None,
executor=executor,
)
if __name__ == '__main__':
from gevent.pywsgi import WSGIServer
http_server = WSGIServer(('0.0.0.0', 8080), application)
http_server.serve_forever()
got error
>python3 wsgi.py
Traceback (most recent call last):
File "C:\QGB\Anaconda3\lib\site-packages\gevent\pywsgi.py", line 999, in handle_one_response
self.run_application()
File "C:\QGB\Anaconda3\lib\site-packages\gevent\pywsgi.py", line 945, in run_application
self.result = self.application(self.environ, self.start_response)
TypeError: handle_request() takes 2 positional arguments but 3 were given
2021-05-11T10:52:03Z {'REMOTE_ADDR': '192.168.43.162', 'REMOTE_PORT': '54957', 'HTTP_HOST': '192.168.43.162:8080', (hidden keys: 25)} failed with TypeError
I want to run aiohttp.web.Application in wsgi
I'm afraid you've got it backwards. This library is for running a WSGI application in iohttp. This means you can run a sync codebase (e.g. Django) alongside an async one.
Each WSGI request is a single-threaded request. Running an async aiohttp handler inside this won't really work, as the handler will still block an entire thread.
On Tue, 11 May 2021 at 12:05, Too large to fit in the margin < @.***> wrote:
I want to run aiohttp.web.Application in wsgi
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/etianen/aiohttp-wsgi/issues/30#issuecomment-838279072, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABEKCCK6MSPOR76XPIVCNDTNEFPHANCNFSM44VD335A .