From 570fafb8d6ee72e27db6fa6178d10df7f9914348 Mon Sep 17 00:00:00 2001 From: percidae Date: Mon, 28 Mar 2022 19:35:48 +0200 Subject: [PATCH] More flexible encoding fix Fix the encoding of the webrequest data if it is not utf-8 - for whatever reason. Do not assume any encoding but do probe it. --- .../waste_collection_schedule/source/avl_ludwigsburg.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/avl_ludwigsburg.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/avl_ludwigsburg.py index ab62421ad..d0736848c 100644 --- a/custom_components/waste_collection_schedule/waste_collection_schedule/source/avl_ludwigsburg.py +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/avl_ludwigsburg.py @@ -115,9 +115,9 @@ def fetch_ics(self, url): ) ) - # Parse ics file, fix broken encoding - if r.encoding=="ISO-8859-1": - dates = self._ics.convert(r.text.encode("latin_1").decode("utf-8")) + # Parse ics file, fix broken encoding dynamically - if necessary + if r.encoding!="uf-8": + dates = self._ics.convert(r.text.encode(r.encoding).decode("utf-8")) else: dates = self._ics.convert(r.text)