Skip to content

Commit

Permalink
Use charset_normalizer from_bytes instead of legacy detect
Browse files Browse the repository at this point in the history
  • Loading branch information
ollo69 committed Apr 28, 2024
1 parent 5fec70c commit 935e27d
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions custom_components/smartthinq_sensors/wideq/core_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import uuid

import aiohttp
from charset_normalizer import detect
from charset_normalizer import from_bytes
import xmltodict

from . import core_exceptions as exc
Expand Down Expand Up @@ -1656,10 +1656,9 @@ async def _load_json_info(self, info_url: str):

content = await self._auth.gateway.core.http_get_bytes(info_url)

# we use charset_normalizer to detect correct encoding and convert to unicode string
encoding = detect(content)["encoding"]
try:
str_content = str(content, encoding, errors="replace")
# we use charset_normalizer to detect correct encoding and convert to unicode string
str_content = str(from_bytes(content).best(), errors="replace")
except (LookupError, TypeError):
# A LookupError is raised if the encoding was not found which could
# indicate a misspelling or similar mistake.
Expand Down

0 comments on commit 935e27d

Please sign in to comment.