2016-09-17 6 views
-1

私はdbからいくつかの文字列を抽出するpython3.5 asyncio + aiomysqlをdockerでラップして使用しています。私は 'ваш-шиномонтаж.рф'を得ることを期待するが、??? - ?????????????代わりに。期待どおりの文字がありません(??? - ?????????? ??)代わりに

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

出力:接続へのparamsを追加することによって解決

<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

:のcharset = 'UTF8'、use_unicode(MySQLのテーブル利用UTF8エンコーディング)ここ

コードであります=真:

関連する問題