From 0a76b0ed15ea6ec68ae5c03b5b6302f9831f8fe9 Mon Sep 17 00:00:00 2001 From: designingSparks Date: Wed, 15 May 2019 16:57:12 +0200 Subject: [PATCH 1/2] Fix crash when decoding non unicode characters in _scan_rsp_data() --- pygatt/backends/bgapi/bgapi.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pygatt/backends/bgapi/bgapi.py b/pygatt/backends/bgapi/bgapi.py index 2f321392..47fc7809 100755 --- a/pygatt/backends/bgapi/bgapi.py +++ b/pygatt/backends/bgapi/bgapi.py @@ -553,8 +553,12 @@ def _scan_rsp_data(self, data): # Field type specific formats if (field_name == 'complete_local_name' or field_name == 'shortened_local_name'): - dev_name = bytearray(field_value).decode("utf-8") - data_dict[field_name] = dev_name + try: + dev_name = bytearray(field_value).decode("utf-8") + except: + pass + else: + data_dict[field_name] = dev_name elif (field_name == 'complete_list_128-bit_service_class_uuids'): if len(field_value) % 16 == 0: # 16 bytes From e8e379fc52d37659b161ea155cd5d750282c0441 Mon Sep 17 00:00:00 2001 From: Christopher Peplin Date: Mon, 27 May 2019 11:53:44 -0400 Subject: [PATCH 2/2] Log when unable to decode --- pygatt/backends/bgapi/bgapi.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pygatt/backends/bgapi/bgapi.py b/pygatt/backends/bgapi/bgapi.py index 47fc7809..29da0b91 100755 --- a/pygatt/backends/bgapi/bgapi.py +++ b/pygatt/backends/bgapi/bgapi.py @@ -556,7 +556,8 @@ def _scan_rsp_data(self, data): try: dev_name = bytearray(field_value).decode("utf-8") except: - pass + log.debug("Failed to decode data as UTF8, " + "returning verbatim") else: data_dict[field_name] = dev_name elif (field_name ==