Django encoding to utf8 not working

I'm a little stuck here. I have this code that unescapes html elements inside text and encodes it in utf8.

import HTMLParser

def clean_text(text):
    htmlparser = HTMLParser.HTMLParser()
    return htmlparser.unescape(
        ' '.join(text.replace('\n', '').split())
    ).replace(';', ',').encode('utf-8').strip()

and I use mysql (God saved me from this!)

and this code works in two projects. in the first project, the code works well, no problem. In another project, the string will be saved as follows:

Die Verbindungen zwischen Dinosauriern und Vögeln immer stärker

It should be

Die Verbindungen zwischen Dinosauriern und Vögeln immer stärker

I use django 1.7 and python 2.7.9 in both projects

What am I missing? mysql collocation utf8_general_ci, and chatset - utf8. Both mysql dbs are the same in settings.

It would be a miracle to solve this problem ... I warmly hug and kiss if someone can help me debug this thing

+4
source share
2

VögelnVögeln Mojibake

  • , , utf8 ().
  • SET NAMES latin1 ( set_charset('latin1') ...), , . ( utf8.)
  • CHARACTER SET utf8, .

, : Django character latin1 mysql python + django + Mysql

Python:

  • # -*- coding: utf-8 -*- - ( )
  • charset='utf8' connect() - bottle_mysql.Plugin? (: "utf-8" "utf8" )
  • , utf8.
  • () (), utf8 .
  • u'...'
  • <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> html
  • Content-Type: text/html; charset = UTF-8 ( HTTP)
  • header ('Content-Type: text/html; charset = UTF-8'); ( PHP )
  • CHARACTER SET utf8 COLLATE utf8_general_ci ( ) MySQL.
  • [[UTF-8 ]]
  • MySQL Connector/Python pyodbc MySQL Connector/ODBC

(@DanielRoseman - - ?)

0

# coding: utf-8, .

-1

Source: https://habr.com/ru/post/1619848/


All Articles