How to solve the error coding (Python and MySQLdb)?

0 like 0 dislike
Help! Started working with Python om recently. Wrote scraper, which pulls the metadata from Google Play. Climb the data and displayed normally (ie, Cyrillic is not spilling), but when I try to record these data into the database (the sounds of the module MySQLdb), once I found the entry with the Cyrillic alphabet in the box throws the following:

_mysql_exceptions.OperationalError: (1366, “Incorrect string value: ‘\\\\xF0\\\\x9F\\\\x8D\\\\x80’ for column ‘title’ at row 1”)

The encoding of the database, tables and fields utf8_general_ci.
Connection to database set as follows:
conn = MySQLdb.connect('localhost', 'VProgramMist', '1998Vm0000', 'mobasta_history', charset='utf8', init_command='SET NAMES UTF8')

Write the data into the database the following:

sql_str = ""INSERT INTO history (app_id, title, score, price, free, iap, iap_range, size, installs, content_rating, date_point, category, collection) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"" cursor.execute(sql_str, ( row['app_id'], row['title'], row['score'], row['price'], row['free'], row['iap'], row['iap_range'], row["size"], row['installs'], row['content_rating'][0],, row['category'][0], row['collection']))

The Version Of Python 3.7
Version Of MySQL - 5.7

PS I Decided to write each a matter of record. Saw that in the database row is written with the Cyrillic alphabet. Ie, something he writes, and something (for example, when it comes to the application "Yule"), it all goes to hell...
by | 70 views

1 Answer

0 like 0 dislike
If True, CHAR and VARCHAR and TEXT columns are returned as Unicode strings, using the configured character set. It is best to set the default encoding in the server configuration, or client configuration (read with read_default_file). If you change the character set after connecting (MySQL-4.1 and later), you'll need to put the correct character set name in connection.charset.

If False, text-like columns are returned as normal strings, but you can always write Unicode strings.

This must be a keyword parameter.

If present, the connection character set will be changed to this character set, if they are not equal. Support for changing the character set requires MySQL-4.1 and later server; if the server is too old, UnsupportedError will be raised. This option implies use_unicode=True, but you can override this with use_unicode=False, though you probably shouldn't.

If not present, the default character set is used.

This must be a keyword parameter.
110,608 questions
257,187 answers
40,796 users