在coroweb.py的add_route函数定义里有
if not asyncio.iscoroutinefunction(fn) and not inspect.isgeneratorfunction(fn): fn = asyncio.coroutine(fn)
python3.7版本以上运行会报错asyncio没有coroutine属性了,如果把这两行注释掉,运行app.py的时候可以打开http://127.0.0.1:9000/,但是页面会报错500 Internet Server Error
查看python报错是ERROR:aiohttp.server:Error handling request
Traceback (most recent call last):
File "D:\PyCharm\awesome-python3-webapp\.venv\Lib\site-packages\aiohttp\web_protocol.py", line 452, in _handle_request
resp = await request_handler(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\PyCharm\awesome-python3-webapp\.venv\Lib\site-packages\aiohttp\web_app.py", line 543, in _handle
resp = await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "D:\PyCharm\awesome-python3-webapp\.venv\Lib\site-packages\aiohttp\web_middlewares.py", line 114, in impl
return await handler(request)
File "D:\PyCharm\awesome-python3-webapp\www\app.py", line 50, in logger
return (await handler(request))
File "D:\PyCharm\awesome-python3-webapp\www\app.py", line 58, in response
r = await handler(request)
File "D:\PyCharm\awesome-python3-webapp\.venv\Lib\site-packages\aiohttp\web_urldispatcher.py", line 205, in handler_wrapper
assert isinstance(result, StreamResponse)
AssertionError
我在handlers.py已经把函数改成协程函数了
@get('/api/users')async def get_api_users():
请问Error handling request这个问题怎么解决呢?
Sign in to make a reply
正义
在coroweb.py的add_route函数定义里有
python3.7版本以上运行会报错asyncio没有coroutine属性了,如果把这两行注释掉,运行app.py的时候可以打开http://127.0.0.1:9000/,但是页面会报错500 Internet Server Error
查看python报错是ERROR:aiohttp.server:Error handling request
Traceback (most recent call last):
File "D:\PyCharm\awesome-python3-webapp\.venv\Lib\site-packages\aiohttp\web_protocol.py", line 452, in _handle_request
resp = await request_handler(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\PyCharm\awesome-python3-webapp\.venv\Lib\site-packages\aiohttp\web_app.py", line 543, in _handle
resp = await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "D:\PyCharm\awesome-python3-webapp\.venv\Lib\site-packages\aiohttp\web_middlewares.py", line 114, in impl
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "D:\PyCharm\awesome-python3-webapp\www\app.py", line 50, in logger
return (await handler(request))
^^^^^^^^^^^^^^^^^^^^^^
File "D:\PyCharm\awesome-python3-webapp\www\app.py", line 58, in response
r = await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "D:\PyCharm\awesome-python3-webapp\.venv\Lib\site-packages\aiohttp\web_urldispatcher.py", line 205, in handler_wrapper
assert isinstance(result, StreamResponse)
AssertionError
我在handlers.py已经把函数改成协程函数了
请问Error handling request这个问题怎么解决呢?