diff --git a/adafruit_azureiot/base64.py b/adafruit_azureiot/base64.py index 4cce82d..ab74bec 100644 --- a/adafruit_azureiot/base64.py +++ b/adafruit_azureiot/base64.py @@ -46,8 +46,8 @@ def _bytes_from_decode_data(data: str): try: return data.encode("ascii") - except: - raise ValueError("string argument should contain only ASCII characters") + except Exception as exc: + raise ValueError("string argument should contain only ASCII characters") from exc def b64encode(toencode: bytes) -> bytes: diff --git a/adafruit_azureiot/device_registration.py b/adafruit_azureiot/device_registration.py index 6b1f8ef..15f85df 100644 --- a/adafruit_azureiot/device_registration.py +++ b/adafruit_azureiot/device_registration.py @@ -49,7 +49,7 @@ class DeviceRegistrationError(Exception): """ def __init__(self, message): - super(DeviceRegistrationError, self).__init__(message) + super().__init__(message) self.message = message @@ -104,7 +104,7 @@ def _loop_assign(self, operation_id, headers) -> str: except ValueError as error: err = "ERROR: " + str(error) + " => " + str(response) self._logger.error(err) - raise DeviceRegistrationError(err) + raise DeviceRegistrationError(err) from error loop_try = 0 @@ -225,7 +225,7 @@ def register_device(self, expiry: int) -> str: except ValueError as error: err = "ERROR: non JSON is received from " + constants.DPS_END_POINT + " => " + str(response) + " .. message : " + str(error) self._logger.error(err) - raise DeviceRegistrationError(err) + raise DeviceRegistrationError(err) from error if "errorCode" in data: err = "DPS => " + str(data) diff --git a/adafruit_azureiot/iot_error.py b/adafruit_azureiot/iot_error.py index 767351c..1ca604b 100644 --- a/adafruit_azureiot/iot_error.py +++ b/adafruit_azureiot/iot_error.py @@ -38,5 +38,5 @@ def __init__(self, message: str): """Create the IoT Error :param str message: The error message """ - super(IoTError, self).__init__(message) + super().__init__(message) self.message = message diff --git a/adafruit_azureiot/iot_mqtt.py b/adafruit_azureiot/iot_mqtt.py index 6d61b91..04f53f2 100644 --- a/adafruit_azureiot/iot_mqtt.py +++ b/adafruit_azureiot/iot_mqtt.py @@ -31,8 +31,8 @@ import gc import json import time -import adafruit_minimqtt as minimqtt -from adafruit_minimqtt import MQTT +import adafruit_minimqtt.adafruit_minimqtt as minimqtt +from adafruit_minimqtt.adafruit_minimqtt import MQTT import adafruit_logging as logging from .iot_error import IoTError from .keys import compute_derived_symmetric_key diff --git a/adafruit_azureiot/iothub_device.py b/adafruit_azureiot/iothub_device.py index c7900d6..bba43ba 100755 --- a/adafruit_azureiot/iothub_device.py +++ b/adafruit_azureiot/iothub_device.py @@ -146,8 +146,8 @@ def __init__(self, socket, iface, device_connection_string: str, token_expires: try: cs_args = device_connection_string.split(DELIMITER) connection_string_values = dict(arg.split(VALUE_SEPARATOR, 1) for arg in cs_args) - except (ValueError, AttributeError): - raise ValueError("Connection string is required and should not be empty or blank and must be supplied as a string") + except (ValueError, AttributeError) as e: + raise ValueError("Connection string is required and should not be empty or blank and must be supplied as a string") from e if len(cs_args) != len(connection_string_values): raise ValueError("Invalid Connection String - Unable to parse") diff --git a/adafruit_azureiot/quote.py b/adafruit_azureiot/quote.py index 5c8dd7a..704188c 100644 --- a/adafruit_azureiot/quote.py +++ b/adafruit_azureiot/quote.py @@ -128,7 +128,7 @@ class Quoter(defaultdict): # of cached keys don't call Python code at all). def __init__(self, safe): """safe: bytes object.""" - super(Quoter, self).__init__() + super().__init__() self.safe = _ALWAYS_SAFE.union(safe) def __missing__(self, b):