From 842827c7fadbb641f70eaf4b886bf0edfa26ecd3 Mon Sep 17 00:00:00 2001 From: Alexander Kozlovsky Date: Thu, 8 Jun 2023 17:01:23 +0200 Subject: [PATCH] Fixes #7406 UnicodeDecodeError in on_tracker_error_alert --- .../libtorrent/download_manager/download.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/tribler/core/components/libtorrent/download_manager/download.py b/src/tribler/core/components/libtorrent/download_manager/download.py index 90d376aba52..e325d1fea38 100644 --- a/src/tribler/core/components/libtorrent/download_manager/download.py +++ b/src/tribler/core/components/libtorrent/download_manager/download.py @@ -312,12 +312,12 @@ def on_tracker_reply_alert(self, alert: lt.tracker_reply_alert): self.tracker_status[alert.url] = [alert.num_peers, 'Working'] def on_tracker_error_alert(self, alert: lt.tracker_error_alert): - self._logger.error(f'On tracker error alert: {alert}') - - # try-except block here is a workaround and has been added to solve - # the issue: "UnicodeDecodeError: invalid continuation byte" + # The try-except block is added as a workaround to suppress UnicodeDecodeError in `repr(alert)`, + # `alert.url` and `alert.msg`. See https://github.com/arvidn/libtorrent/issues/143 try: + self._logger.error(f'On tracker error alert: {alert}') url = alert.url + peers = self.tracker_status[url][0] if url in self.tracker_status else 0 if alert.msg: status = 'Error: ' + alert.msg @@ -330,8 +330,7 @@ def on_tracker_error_alert(self, alert: lt.tracker_error_alert): self.tracker_status[url] = [peers, status] except UnicodeDecodeError as e: - self._logger.exception(e) - return + self._logger.warning(f'UnicodeDecodeError in on_tracker_error_alert: {e}') def on_tracker_warning_alert(self, alert: lt.tracker_warning_alert): self._logger.warning(f'On tracker warning alert: {alert}')