Closed
Description
I'm working against the latest version of this with the breaking changes from #21. I've made the required changes to set the socket and changed the call to __init__
.
I'm hitting a bug with connecting. When I call connect
I get an error:
Traceback (most recent call last):
File "code.py", line 120, in <module>
File "azureiotmqtt.py", line 523, in connect
File "azureiotmqtt.py", line 219, in _loopAssign
File "azureiotmqtt.py", line 439, in _mqttConnect
File "azureiotmqtt.py", line 121, in _createMQTTClient
File "adafruit_minimqtt.py", line 220, in connect
ValueError: need more than 1 values to unpack
Digging into the code I see this at line 215:
try:
proto, dummy, self.broker, path = self.broker.split("/", 3)
# replace spaces in path
path = path.replace(" ", "%20")
except ValueError:
proto, dummy, self.broker = self.broker.split("/", 2)
path = ""
if proto == "http:":
self.port = MQTT_TCP_PORT
elif proto == "https:":
self.port = MQTT_TLS_PORT
else:
raise ValueError("Unsupported protocol: " + proto)
It looks like the code is checking for http://
or https://
at the start of the broker name, and using this to get the port. This looks wrong to me:
- I've already set the port in the call to
__init__
so there is no need to look it up. - I'm using MQTT, not over http so my broker name will never start with
http://
or 'https://`, so this code will always throw an error.
My workaround is to manually prepend https://
to my broker name, which is less than ideal.
Looking at the previous version of the code, this wasn't there and there was no checking for the port, assuming the user had set it. I guess this is to work around the user not setting the port.