michaelliao / awesome-python3-webapp

小白的Python入门教程实战篇
https://liaoxuefeng.com/books/python/
GNU General Public License v3.0
2.4k stars 2.8k forks source link

day10: 点击注册后页面出现:网络好像出问题了 (HTTP 500) #38

Open tianke0711 opened 6 years ago

tianke0711 commented 6 years ago

我按照廖老师的教程,想注册一个用户名后点击提交有错误,希望帮我解决一下: 点击后页面出现:网络好像出问题了 (HTTP 500)

INFO:root:server started at http://127.0.0.1:9000... INFO:root:Request: GET /register INFO:root:Response handler... INFO:root:call with args: {} INFO:aiohttp.access:127.0.0.1 - - [14/Dec/2017:07:54:29 +0000] "GET /register HTTP/1.1" 200 6587 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.1.2 Safari/603.3.8" INFO:root:Request: POST /api/users INFO:root:Response handler... INFO:root:call with args: {'email': 'ka@sina.com', 'name': 'ka', 'passwd': '4ff03fb6437edad36af5fd180c42ec483983c1fc'} /Users/k.den/awesome-python3-webapp/www/handlers.py:132: RuntimeWarning: coroutine 'Model.findAll' was never awaited users = yield from User.findAll('email=?', [email]) ERROR:aiohttp.server:Error handling request Traceback (most recent call last): File "/anaconda3/lib/python3.6/site-packages/aiohttp/web_protocol.py", line 417, in start resp = yield from self._request_handler(request) File "/anaconda3/lib/python3.6/site-packages/aiohttp/web.py", line 289, in _handle resp = yield from handler(request) File "app.py", line 43, in logger return (await handler(request)) File "app.py", line 61, in response r = await handler(request) File "/anaconda3/lib/python3.6/site-packages/aiohttp/web_urldispatcher.py", line 111, in handler_wrapper result = yield from result File "/Users/den/awesome-python3-webapp/www/coroweb.py", line 138, in call r = yield from self._func(**kw) File "/anaconda3/lib/python3.6/asyncio/coroutines.py", line 213, in coro res = yield from res File "/Users/den/awesome-python3-webapp/www/handlers.py", line 132, in api_register_user users = yield from User.findAll('email=?', [email]) TypeError: cannot 'yield from' a coroutine object in a non-coroutine generator

luyangong commented 6 years ago

函数前面加async;再把yield from 改成await就行了