-1

I have a few questions about character encoding between MySQL, python, and HTML.

Here's the situation. I have a python script that gets information from a website and loads it into a MySQL table. Then I have a PHP and HTML frontend that takes the data from the table and loads it into an HTML table. I'm running into what I believe are just some encoding incongruencies between all these languages and platforms. I've included pictures of the result of running the python script in shell, as well as the resulting output in MySQL and finally on the HTML frontend.

When I load from python to MySQL, it does fine with symbols like 'degrees' or 'micro' but doesn't like 'ohms' for example (that's what I believe is causing the error statement in the python shell). And when I go from MySQL to HTML, it doesn't like any of the special characters like 'degrees', 'ohms', or 'micro'. What is happening here and is there a way to fix it?

Hoping someone can shed some light on this as I am very confused and somewhat of a newbie when dealing with character encoding.

enter image description hereenter image description hereenter image description here

Jonny1998
  • 107
  • 1
  • 1
  • 13

2 Answers2

1

Try changing mysql database encoding.

ALTER TABLE tablename CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;

How to convert an entire MySQL database characterset and collation to UTF-8?

Adelina
  • 10,915
  • 1
  • 38
  • 46
  • Well, I've tried executing your code but it's taking forever to load. Any suggestions? – Jonny1998 Jul 24 '18 at 16:32
  • How big is your table? And if this is the fix, it might only work for new records – Adelina Jul 24 '18 at 16:35
  • As of right now my table is only 3 rows and about 12 columns. Once I can get through these errors and import more data, it will become a much larger table. – Jonny1998 Jul 24 '18 at 16:38
  • Should take few seconds then. Try: ALTER DATABASE databasename CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE tablename CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; – Adelina Jul 24 '18 at 16:42
1

It's not bad. MySQL just write special characters as e.g. ð but when you select it back to you application it show it correctly.

enter image description here

I pasted example for HTML page but for Python It's same :)


But when it's showing question mark symbol there is problem with Charset so check if your database have utf8_general_ci coding

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
WebCoder
  • 62
  • 10