astrorafael / twisted-mqtt

MQTT Client protocol for Twisted.
MIT License
30 stars 11 forks source link

Failure: exceptions.UnboundLocalError: local variable 'topic' referenced before assignment #6

Closed fanff closed 7 years ago

fanff commented 7 years ago

Hello,

I have an error using the protocol.subscribe function that say :

Failure: exceptions.UnboundLocalError: local variable 'topic' referenced before assignment

The failure has no frame, so no stack trace.

Also I can find some weird things in the pubsub.py file but it seems not related

https://github.com/astrorafael/twisted-mqtt/blob/master/mqtt/client/pubsubs.py#L514 https://github.com/astrorafael/twisted-mqtt/blob/master/mqtt/client/pubsubs.py#L528

Worth noticing that I try to subscribe to 4 channels so i do like

for topic in topics:
    d = self.protocol.subscribe(topics=topic, qos=1)

# all d are then put in a DeferredList and all result are errors.

Thanks in advance for answer.

astrorafael commented 7 years ago

Hi

Thank you very much for your interest in my library.

The easy things first: The 'weird' lines are indeed redundant code, since lines 396-397 makes sure that requests.topcis is already a list. I'll fix it shortly.

Regarding to multiple subscriptions, you are probably missing this:

# We are issuing 4 subscriptions in a row
# Subscription requests beyond window size 
 # invoke errback with MQTTWindowError exception
self.protocol.setWindowSize(4) 

Regarding the unboundLocalError, if you could provide me with a small example showing how it fails, I could have a look at it. If I cannot reproduce it, chances that I can fix it are small