-1

I am using python3.5 asyncio+aiomysql wrapped in docker to extract some strings from my db. I expect to get 'ваш-шиномонтаж.рф' but got ???-??????????.?? instead. (Mysql table use utf-8 encoding.)

Here is a code:

# 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()

the output:

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

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

what could be the problem?
Evg
  • 2,978
  • 5
  • 43
  • 58
  • The answer is given for php but it makes no difference, the same suggestions keep for python as well http://stackoverflow.com/questions/279170/utf-8-all-the-way-through – zerkms Sep 17 '16 at 00:51

1 Answers1

0

Solved by adding params to connection: charset='utf8', use_unicode=True:

Evg
  • 2,978
  • 5
  • 43
  • 58