diff --git a/ChangeLog.txt b/ChangeLog.txt index a455b2c627469adc78ebc150ba12035173dcd153..6b3db7cc2eaeac306d948a70c2f80b9213c4ced3 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -29,6 +29,8 @@ v1.6.0 - 2021-xx-xx - Fix connecting with MQTT v5 to a broker that doesn't support MQTT v5. Closes #566. - Removed ancient Mosquitto compatibility class. +- Fix exception on calling Client(client_id="", clean_session=False). + Closes #520. v1.5.1 - 2020-09-22 diff --git a/src/paho/mqtt/client.py b/src/paho/mqtt/client.py index 81d8ecbd213916f9571b254d351b1c8b49f935d1..0557e7159e47a980d485724921e5d778adce745e 100644 --- a/src/paho/mqtt/client.py +++ b/src/paho/mqtt/client.py @@ -506,17 +506,6 @@ class Client(object): mechanism. Set to "tcp" to use raw TCP, which is the default. """ - if protocol == MQTTv5: - if clean_session is not None: - raise ValueError('Clean session is not used for MQTT 5.0') - else: - if clean_session is None: - clean_session = True - if not clean_session and (client_id == "" or client_id is None): - raise ValueError( - 'A client id must be provided if clean session is False.') - self._clean_session = clean_session - if transport.lower() not in ('websockets', 'tcp'): raise ValueError( 'transport must be "websockets" or "tcp", not %s' % transport) @@ -529,6 +518,18 @@ class Client(object): self._keepalive = 60 self._connect_timeout = 5.0 self._client_mode = MQTT_CLIENT + + if protocol == MQTTv5: + if clean_session is not None: + raise ValueError('Clean session is not used for MQTT 5.0') + else: + if clean_session is None: + clean_session = True + if not clean_session and (client_id == "" or client_id is None): + raise ValueError( + 'A client id must be provided if clean session is False.') + self._clean_session = clean_session + # [MQTT-3.1.3-4] Client Id must be UTF-8 encoded string. if client_id == "" or client_id is None: if protocol == MQTTv31: