Python read database data, read out the Chinese garbled problem

Source: Internet
Author: User

Recently encountered Python read database data, read out the Chinese garbled problem,

The basic of Web search is:

"1. python file Set encoding utf-8 (file preceded by #encoding =utf-8)
2. mysql Database charset=utf-8
3. Python connection mysql is plus parameter Charset=utf8
4. Set Python's default encoding to Utf-8 (sys.setdefaultencoding (utf-8))

These are not resolved after one attempt. Go to the database to see the next, found that the Chinese garbled field type is varchar. And then think of the difference between varchar and nvarchar.

After use

SELECT CONVERT (nvarchar (100), field)

Translate the field to nvarchar, debug, find that the field in the Debug window is normal for Chinese.

Python read database data, read out the Chinese garbled problem

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.