Sep-08-2017, 01:54 AM
import sys reload(sys) sys.setdefaultencoding('utf8') import pyodbc driver = '{ODBC Driver 13 for SQL Server}' cnxn = pyodbc.connect('DRIVER='+driver+';SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password+';CHARSET=SJIS') #cnxn.setencoding(unicode, encoding='utf-8') cursor = cnxn.cursor() cursor.execute("select ... where q_contract_summary.identifier='" + identifier + "'") row = cursor.fetchone() while row: sys.stdout.write(str(row[0]).decode('unicode_escape')) #print(str(row[0]).decode('utf-8') + " " + unicode(str(row[1]), "utf-8")) row = cursor.fetchone()I see in my console is:
Quote:a?¢a??a?âªa??a??c?°a¢?tedchou-MacBook-Air:~ ted.chou$ python test.py
a?¢a??a?âªa??a??c?°a¢?tedchou-MacBook-Air:~ ted.chou$ python test.py
a?¢a??a?âªa??a??c?°a¢?tedchou-MacBook-Air:~ ted.chou$
I believe that this is the encoding problem, could anyone guide me in the right direction?
Thank you so much!