A Unicode problem. Anyone can help?

82 views
Skip to first unread message

赵康

unread,
Mar 22, 2020, 8:50:09 AM3/22/20
to PyMySQL Users
There is a MySQL database, which is created with latin1 character-set by default. However, the data stored in the database is orgnized with another character-set. In fact, it is GBK. When I use the GBK
character-set to query the database, it is just OK.

But when I use Python 3 and PyMySQL, a problem occurs. The dafault character-set is utf-8, and all of the query are failed.
So anyone can help to solve this problem?
And I cannot change this badly-created database.

NKM

unread,
Mar 22, 2020, 10:13:31 AM3/22/20
to pymysq...@googlegroups.com
can you send snap shot of your error.


Regard :
Prof. Nitin K. Mishra 


--
You received this message because you are subscribed to the Google Groups "PyMySQL Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pymysql-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pymysql-users/f3c6d782-64c8-491d-a860-65cf7f133f82%40googlegroups.com.

赵康

unread,
Mar 22, 2020, 11:36:41 AM3/22/20
to pymysq...@googlegroups.com
thank you very much first, and I would show you below:

1.the code and query results are shown in the figure.
I make the connection to MySQL without specifying the charset. And the database uses the latin1 charset. In fact, the data stored in this database is with GBK charset, which is used commonly in China Mainland.
image.png

2. When I make a query, some errors occur, just shown below.
I know from the figure that the utf-8 codec should be the default charset for pymysql. I fetch data with GBK charset, so the error is reasonable.
image.png

3. the question is how I can fetch the right data?
when I use charset GBK , I could get data,  but there are wrong characters like '????", which should be Chinese like"山东".
image.png

NKM <nmish...@gmail.com> 于2020年3月22日周日 下午10:13写道:
Reply all
Reply to author
Forward
0 new messages