From 0311e03d0d16b1f568d9f94badd394d77b50dea3 Mon Sep 17 00:00:00 2001 From: Robert Chmielowiec Date: Tue, 16 Feb 2021 00:17:44 +0100 Subject: [PATCH 1/2] Fix socket options for websocket transport Fixing AttributeError: 'WebsocketWrapper' object has no attribute 'setsockopt' --- asyncio_mqtt/client.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/asyncio_mqtt/client.py b/asyncio_mqtt/client.py index cbe3887..54d6ef7 100644 --- a/asyncio_mqtt/client.py +++ b/asyncio_mqtt/client.py @@ -78,7 +78,9 @@ async def connect(self, *, timeout=10): loop = asyncio.get_running_loop() await loop.run_in_executor(None, self._client.connect, self._hostname, self._port, 60) # paho.mqttClient.socket() return non-None after the call to connect. - self._client.socket().setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 2048) + client_socket = self._client.socket() + if type(client_socket) is not mqtt.WebsocketWrapper: + client_socket.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 2048) # paho.mqtt.Client.connect may raise one of several exceptions. # We convert all of them to the common MqttError for user convenience. # See: https://github.com/eclipse/paho.mqtt.python/blob/v1.5.0/src/paho/mqtt/client.py#L1770 From d26cb995ffc241453999f663b9ba82f505b07d30 Mon Sep 17 00:00:00 2001 From: Robert Chmielowiec Date: Tue, 16 Feb 2021 11:24:12 +0100 Subject: [PATCH 2/2] Use isinstance instead of type --- asyncio_mqtt/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asyncio_mqtt/client.py b/asyncio_mqtt/client.py index 54d6ef7..fe3cd25 100644 --- a/asyncio_mqtt/client.py +++ b/asyncio_mqtt/client.py @@ -79,7 +79,7 @@ async def connect(self, *, timeout=10): await loop.run_in_executor(None, self._client.connect, self._hostname, self._port, 60) # paho.mqttClient.socket() return non-None after the call to connect. client_socket = self._client.socket() - if type(client_socket) is not mqtt.WebsocketWrapper: + if not isinstance(client_socket, mqtt.WebsocketWrapper): client_socket.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 2048) # paho.mqtt.Client.connect may raise one of several exceptions. # We convert all of them to the common MqttError for user convenience.