A
A
Artyom2018-04-15 13:11:37
MySQL
Artyom, 2018-04-15 13:11:37

Python + MySQL: how to enter Cyrillic text into a table?

When I try to enter Cyrillic text into the MySQL database, I get an error

UnicodeEncodeError: 'latin-1' codec can't encode characters in position 26-32: ordinal not in range(256)

And connecting to the database with the indication "charset="utf8", use_unicode=True" or with init_command='SET NAMES UTF8', when entering the text, I get
_mysql_exceptions.OperationalError: (1366, "Incorrect string value: '\\xD1\\x80\\xD0\\xBF\\xD1\\x80...' for column 'text1' at row 1")

How to fix it? (Python version 3)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Fixid, 2018-04-15
@Fixid

To start:

# -*- coding: utf-8 -*-
# !/usr/bin/env python

When connecting to the database "charset="utf8"
You have the database itself in latin-1, you must either change it to utf8 or recreate the database

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question