"Go" python mysql database ' latin-1 ' codec can ' t encode character error problem resolution

Source: Internet
Author: User
Tags python mysql

Unicodeencodeerror: ' latin-1 ' codec can ' t encode character

"Unicodeencodeerror: ' latin-1 ' codec can ' t encode character ..."

This was because mysqldb normally tries to encode Everythin to latin-1. This can is fixed by executing the following commands right after you ' ve etablished the connection:

Db.set_character_set ('utf8') dbc.execute ('set NAMES UTF8; ') Dbc.execute ('set CHARACTER set UTF8; ' ) Dbc.execute ('SET Character_set_connection=utf8; ')

The "DB" is the result of MySQLdb.connect, and "DBC" is the result of the Db.cursor ().

This means that mysqldb will normally try to convert everything to latin1 character set processing so the way to do this is to set the charset of the connection and the cursor to the encoding you want, such as UTF8

DB is a connection connection, DBC is a database cursor

Http://stackoverflow.com/questions/3942888/unicodeencodeerror-latin-1-codec-cant-encode-character

"Go" python mysql database ' latin-1 ' codec can ' t encode character error problem resolution

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.