没有预期的字符(??? - ??????????? ??

时间:2016-09-17 00:49:51

标签: mysql encoding docker character-encoding python-3.5

我正在使用包含在docker中的python3.5 asyncio + aiomysql从我的数据库中提取一些字符串。我希望得到'ваш-шиномонтаж.рф',但得到了??? - ????????????代替。 (Mysql表使用utf-8编码。)

这是一段代码:

# encoding: utf-8
import asyncio
from aiomysql import create_pool

async def get_pool(loop):
    return await create_pool(host='127.0.0.1', port=3306, user='dbu', password='pwd', db='db', loop=loop)


async def get_sites(pool):
    async with pool.acquire() as conn:
        async with conn.cursor() as cur:
            await cur.execute(
                "select canonic_domain from site where id=1132",
                ()) 
            sites = await cur.fetchall()
            for s in sites:
                print(type(s[0]))
                print(s[0])



            return sites



def process():
    loop = asyncio.get_event_loop()
    pool = loop.run_until_complete(loop.create_task(get_pool(loop)))
    sites = loop.run_until_complete(loop.create_task(get_sites(pool)))

if __name__ == "__main__":

    process()

输出:

<class 'str'>
???-??????????.??

I expect:
<class 'str'>
'ваш-шиномонтаж.рф'

what could be the problem?

1 个答案:

答案 0 :(得分:0)

通过向连接添加params来解决:charset ='utf8',use_unicode = True: