Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: Error Reading unicode word from MySQL


I'm new to python, I have a trouble reading data from Mysql. Here in mysql, my table stores destination:

|id | Destination|
|1 |Hà Nội |
|2 |Hồ Chí Minh |

... but when I read it from python its return this: ' u\'H\xe0 N\u1ed9i\'' for Hà Nội. Is there any way to convert it back to original string: 'Hà Nội' here is my code to open connection and select data:

def __init__(self):
self.mySQLConnection = mysql.connector.connect(user='root', password='', host='localhost',database='traveltrend',charset='utf8',use_unicode=True)
self.cursor = self.mySQLConnection.cursor(buffered=True)

def getDest(self):
self.cursor.execute("SELECT ID, ThanhPho FROM diadiem ")
row = self.cursor.fetchone()
while row is not None:
request = str(row)
request = request.strip('()')
request = request.split(',')
encoding = "utf-8"
on_error = "replace"
place= request[1].encode(encoding,on_error)

Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered

This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: Error Reading unicode word from MySQL


Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription