From dd4a46459b754415ea688f8baa04c5ff2800f932 Mon Sep 17 00:00:00 2001 From: Joseph Klix Date: Thu, 17 Feb 2022 11:53:53 -0800 Subject: [PATCH 1/2] change append to extend to fix bytestream error --- AWSIoTPythonSDK/core/greengrass/discovery/providers.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/AWSIoTPythonSDK/core/greengrass/discovery/providers.py b/AWSIoTPythonSDK/core/greengrass/discovery/providers.py index 646d79d..47235c9 100644 --- a/AWSIoTPythonSDK/core/greengrass/discovery/providers.py +++ b/AWSIoTPythonSDK/core/greengrass/discovery/providers.py @@ -203,7 +203,7 @@ def discover(self, thingName): """ **Description** - + Perform the discovery request for the given Greengrass aware device thing name. **Syntax** @@ -246,9 +246,9 @@ def _create_tcp_connection(self): def _create_ssl_connection(self, sock): self._logger.debug("Creating ssl connection...") - + ssl_protocol_version = ssl.PROTOCOL_SSLv23 - + if self._port == 443: ssl_context = SSLContextBuilder()\ .with_ca_certs(self._ca_path)\ @@ -368,7 +368,7 @@ def _receive_until(self, ssl_sock, criteria_function, extra_data=None): number_bytes_read = 0 while True: # Python does not have do-while try: - response.append(self._convert_to_int_py3(ssl_sock.read(1))) + response.extend(self._convert_to_int_py3(ssl_sock.read(1))) number_bytes_read += 1 except socket.error as err: if err.errno == ssl.SSL_ERROR_WANT_READ or err.errno == ssl.SSL_ERROR_WANT_WRITE: From 4b80923ca0bbed5be220ee4dd6e9f431f332fafd Mon Sep 17 00:00:00 2001 From: Joseph Klix Date: Tue, 1 Mar 2022 11:33:29 -0800 Subject: [PATCH 2/2] correctly handle bytearray with extend or append --- AWSIoTPythonSDK/core/greengrass/discovery/providers.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/AWSIoTPythonSDK/core/greengrass/discovery/providers.py b/AWSIoTPythonSDK/core/greengrass/discovery/providers.py index 47235c9..b09dfed 100644 --- a/AWSIoTPythonSDK/core/greengrass/discovery/providers.py +++ b/AWSIoTPythonSDK/core/greengrass/discovery/providers.py @@ -366,9 +366,14 @@ def _receive_until(self, ssl_sock, criteria_function, extra_data=None): start_time = time.time() response = bytearray() number_bytes_read = 0 + ssl_sock_tmp = None while True: # Python does not have do-while try: - response.extend(self._convert_to_int_py3(ssl_sock.read(1))) + ssl_sock_tmp = self._convert_to_int_py3(ssl_sock.read(1)) + if ssl_sock_tmp is list: + response.extend(ssl_sock_tmp) + else: + response.append(ssl_sock_tmp) number_bytes_read += 1 except socket.error as err: if err.errno == ssl.SSL_ERROR_WANT_READ or err.errno == ssl.SSL_ERROR_WANT_WRITE: