2016-09-17 65 views
-1

我使用python3.5 ASYNCIO + aiomysql包裹在泊塢窗提取從我的分貝一些字符串。我希望得到'ваш-шиномонтаж.рф',但有??? - ??????????。代替。 (MySQL表使用UTF8編碼)沒有如預期字符

下面是一個代碼:

# 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? 
+0

給出的答案是PHP的,但它沒有什麼區別,同樣建議保持爲Python以及http://stackoverflow.com/questions/279170/utf-8-all-the-way-through – zerkms

回答

0

通過添加PARAMS到連接解決:字符集= 'UTF-8',use_unicode = TRUE: