| 1 |
Frequently asked questions |
| 2 |
=========================== |
| 3 |
|
| 4 |
|
| 5 |
Is UTF-8 everywhere already? |
| 6 |
---------------------------- |
| 7 |
|
| 8 |
Not really, that is a dangerous assumption. Looking at https://w3techs.com/technologies/overview/character_encoding may |
| 9 |
seem like encoding detection is a thing of the past but not really. Solo based on 33k websites, you will find |
| 10 |
3,4k responses without predefined encoding. 1,8k websites were not UTF-8, merely half! |
| 11 |
|
| 12 |
This statistic (w3techs) does not offer any ponderation, so one should not read it as |
| 13 |
"I have a 97 % chance of hitting UTF-8 content on HTML content". |
| 14 |
|
| 15 |
(2021 Top 1000 sites from 80 countries in the world according to Data for SEO) https://github.com/potiuk/test-charset-normalizer |
| 16 |
|
| 17 |
First of all, neither requests, chardet or charset-normalizer are dedicated to HTML content. |
| 18 |
The detection concern every text document, like SubRip Subtitle files for instance. And by my own experiences, I never had |
| 19 |
a single database using full utf-8, many translated subtitles are from another era and never updated. |
| 20 |
|
| 21 |
It is so hard to find any stats at all regarding this matter. Users' usages can be very dispersed, so making |
| 22 |
assumptions are unwise. |
| 23 |
|
| 24 |
The real debate is to state if the detection is an HTTP client matter or not. That is more complicated and not my field. |
| 25 |
|
| 26 |
Some individuals keep insisting that the *whole* Internet is UTF-8 ready. Those are absolutely wrong and very Europe and North America-centered, |
| 27 |
In my humble experience, the countries in the world are very disparate in this evolution. And the Internet is not just about HTML content. |
| 28 |
Having a thorough analysis of this is very scary. |
| 29 |
|
| 30 |
Should I bother using detection? |
| 31 |
-------------------------------- |
| 32 |
|
| 33 |
In the last resort, yes. You should use well-established standards, eg. predefined encoding, at all times. |
| 34 |
When you are left with no clue, you may use the detector to produce a usable output as fast as possible. |
| 35 |
|
| 36 |
Is it backward-compatible with Chardet? |
| 37 |
--------------------------------------- |
| 38 |
|
| 39 |
If you use the legacy `detect` function, |
| 40 |
Then this change is mostly backward-compatible, exception of a thing: |
| 41 |
|
| 42 |
- This new library support way more code pages (x3) than its counterpart Chardet. |
| 43 |
- Based on the 30-ich charsets that Chardet support, expect roughly 80% BC results |
| 44 |
|
| 45 |
We do not guarantee this BC exact percentage through time. May vary but not by much. |
| 46 |
|
| 47 |
Isn't it the same as Chardet? |
| 48 |
----------------------------- |
| 49 |
|
| 50 |
The objective is the same, provide you with the best answer (charset) we can given any sequence of bytes. |
| 51 |
The method actually differs. |
| 52 |
|
| 53 |
We do not "train" anything to build a probe for a specific encoding. In addition to finding any languages (intelligent |
| 54 |
design) by some rudimentary statistics (character frequency ordering) we built a mess detector to assist the language |
| 55 |
detection. |
| 56 |
|
| 57 |
Any code page supported by your cPython is supported by charset-normalizer! It is that simple, no need to update the |
| 58 |
library. It is as generic as we could do. |
| 59 |
|
| 60 |
I can't build standalone executable |
| 61 |
----------------------------------- |
| 62 |
|
| 63 |
If you are using ``pyinstaller``, ``py2exe`` or alike, you may be encountering this or close to: |
| 64 |
|
| 65 |
ModuleNotFoundError: No module named 'charset_normalizer.md__mypyc' |
| 66 |
|
| 67 |
Why? |
| 68 |
|
| 69 |
- Your package manager picked up a optimized (for speed purposes) wheel that match your architecture and operating system. |
| 70 |
- Finally, the module ``charset_normalizer.md__mypyc`` is imported via binaries and can't be seen using your tool. |
| 71 |
|
| 72 |
How to remedy? |
| 73 |
|
| 74 |
If your bundler program support it, set up a hook that implicitly import the hidden module. |
| 75 |
Otherwise, follow the guide on how to install the vanilla version of this package. (Section: *Optional speedup extension*) |