[英]How to handle RuntimeWarning: coroutine 'new_account' was never awaited
Whenever I start web.py and go to localhost:8080/register
I get this error.每当我启动web.py并转到
localhost:8080/register
我都会收到此错误。 It's part of a Flash game.它是 Flash 游戏的一部分。
web.py:75: RuntimeWarning: coroutine 'new_account' was never awaited
uid, password = utils.bot_common.new_account(app["redis"])
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Error handling request
Traceback (most recent call last):
File "/root/.local/lib/python3.7/site-packages/aiohttp/web_protocol.py", line418, in start
resp = await task
File "/root/.local/lib/python3.7/site-packages/aiohttp/web_app.py", line 458,in _handle
resp = await handler(request)
File "/root/.local/lib/python3.7/site-packages/aiohttp/web_middlewares.py", lne 119, in impl
return await handler(request)
File "/root/.local/lib/python3.7/site-packages/aiohttp_session/__init__.py", ine 154, in factory
response = await handler(request)
File "web.py", line 75, in register
uid, password = utils.bot_common.new_account(app["redis"])
TypeError: cannot unpack non-iterable coroutine object
above error points to web.py Line 75:上面的错误指向web.py第 75 行:
@routes.get("/register")
async def register(request):
if not registation:
return web.Response(text="Регистрация отключена")
uid, password = utils.bot_common.new_account(app["redis"])
return web.Response(text=f"Аккаунт создан, ваш логин - {uid}, "
f"пароль - {password}")
Some more information from bot_commony.py register bot:来自bot_common.py注册机器人的更多信息:
import string
import random
def random_string(string_length=20):
letters = string.ascii_letters
return ''.join(random.choice(letters) for i in range(string_length))
async def new_account(redis):
await redis.incr("uids")
uid = await redis.get("uids")
pipe = redis.pipeline()
pipe.set(f"uid:{uid}:lvt", 0)
pipe.sadd(f"rooms:{uid}", "livingroom")
pipe.rpush(f"rooms:{uid}:livingroom", "#livingRoom", 1)
for i in range(1, 6):
pipe.sadd(f"rooms:{uid}", f"room{i}")
pipe.rpush(f"rooms:{uid}:room{i}", f"Комната {i}", 2)
await pipe.execute()
return uid
new_account
returns a coroutine, hence new_account
返回一个协程,因此
TypeError: cannot unpack non-iterable coroutine object
Coroutines need to be awaited (or wrapped in a task).协程需要等待(或包装在任务中)。 To fix this specific
TypeError
, you need to update your code to要修复此特定
TypeError
,您需要将代码更新为
uid, password = await untold.bot_common.new_account(app["redis"])
Once you've made this change, I suspect you'll get a new TypeError
:一旦你做了这个改变,我怀疑你会得到一个新的
TypeError
:
TypeError: cannot unpack non-iterable int object
This is because new_account
returns a single value: uid
.这是因为
new_account
返回一个值: uid
。 Based on await redis.incr("uids")
, it looks like you have an integer, not a two-character string or a container with two values in it.基于
await redis.incr("uids")
,看起来您有一个整数,而不是两个字符的字符串或其中包含两个值的容器。 You'll either need to change the line in register
to您要么需要将
register
的行更改为
uid = await untold.bot_common.new_account(app["redis"])
or you'll need to change new_account
to return multiple values或者您需要更改
new_account
以返回多个值
return uid, "some password"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.