Skip to content

Commit 793e9bc

Browse files
authored
Merge pull request #30 from jimbobbennett/fix_broker
Using a copy of the broker name when splitting
2 parents bd24155 + be1ea86 commit 793e9bc

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

adafruit_minimqtt.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,11 @@ def connect(self, clean_session=True):
223223
224224
"""
225225
try:
226-
proto, dummy, self.broker, path = self.broker.split("/", 3)
226+
proto, dummy, broker, path = self.broker.split("/", 3)
227227
# replace spaces in path
228228
path = path.replace(" ", "%20")
229229
except ValueError:
230-
proto, dummy, self.broker = self.broker.split("/", 2)
230+
proto, dummy, broker = self.broker.split("/", 2)
231231
path = ""
232232
if proto == "http:":
233233
self.port = MQTT_TCP_PORT
@@ -236,13 +236,11 @@ def connect(self, clean_session=True):
236236
else:
237237
raise ValueError("Unsupported protocol: " + proto)
238238

239-
if ":" in self.broker:
240-
self.broker, port = self.broker.split(":", 1)
239+
if ":" in broker:
240+
broker, port = broker.split(":", 1)
241241
port = int(port)
242242

243-
addr = _the_sock.getaddrinfo(self.broker, self.port, 0, _the_sock.SOCK_STREAM)[
244-
0
245-
]
243+
addr = _the_sock.getaddrinfo(broker, self.port, 0, _the_sock.SOCK_STREAM)[0]
246244
self._sock = _the_sock.socket(addr[0], addr[1], addr[2])
247245
self._sock.settimeout(15)
248246
if self.port == 8883:
@@ -251,7 +249,7 @@ def connect(self, clean_session=True):
251249
self.logger.debug(
252250
"Attempting to establish secure MQTT connection..."
253251
)
254-
self._sock.connect((self.broker, self.port), _the_interface.TLS_MODE)
252+
self._sock.connect((broker, self.port), _the_interface.TLS_MODE)
255253
except RuntimeError as e:
256254
raise MMQTTException("Invalid broker address defined.", e)
257255
else:

0 commit comments

Comments
 (0)