最新的github上的Basic Example运行不起来

来源:6-2 aiomysql完成数据的读写....

慕无忌King

2019-04-19

在github上的最新的aiomysql上的Basic Example代码和视频中的不太一样,现在是这个样子的,

async def test_example(loop):
    pool = await aiomysql.create_pool(host='127.0.0.1', port=3306,
                                      user='root', password='123456789',
                                      db='message', charset="utf8")
    async with pool.acquire() as conn:
        async with conn.cursor() as cur:
            await cur.execute("SELECT * FROM message;")
            print(cur.description)
            (r,) = await cur.fetchone()
            assert r == 42
    pool.close()
    await pool.wait_closed()


loop = asyncio.get_event_loop()
loop.run_until_complete(test_example(loop))

其中数据库名,密码已经替换成本地的了。但是,运行以后报错。
如图
图片描述
请问老师,这个是什么问题呢

写回答

2回答

你笑就好

2019-09-11

这个已经解决, fetchone那行, 你改成r = await cur.fetchone(), 在把下面的assert断言删除掉就可以了, 源代码为什么这么写, 我也不太清楚

0
0

bobby

2019-04-22

你下载的是哪里的代码?是课程中提供的源码吗?

0
0

Tornado从入门到进阶 打造支持高并发的技术论坛

异步IO并发编程/Form,ORM/aiomysql、peewee-async/epoll

593 学习 · 350 问题

查看课程