njouanin / hbmqtt

MQTT client/broker using Python asynchronous I/O
MIT License
800 stars 188 forks source link

Incorrect error message when not provide the protocol #164

Open rondou opened 5 years ago

rondou commented 5 years ago

Missing protocol information during connection, the error message is "writer object is none" but actually, it occurs without protocol.

C = MQTTClient()
yield from C.connect('test.mosquitto.org/')
@asyncio.coroutine
def reconnect(self, cleansession=None):
    """
    Reconnect a previously connected broker.

    Reconnection tries to establish a network connection and send a `CONNECT <http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718028>`_ message.
    Retries interval and attempts can be controled with the ``reconnect_max_interval`` and ``reconnect_retries`` configuration parameters.

    This method is a *coroutine*.

    :param cleansession: clean session flag used in MQTT CONNECT messages sent for reconnections.
    :return: `CONNACK <http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718033>`_ return code
    :raise: :class:`hbmqtt.client.ConnectException` if re-connection fails after max retries.
    """
    ...............

>           raise ConnectException("Too many connection attempts failed")
E           hbmqtt.client.ConnectException: Too many connection attempts failed

../../../.local/share/virtualenvs/uni-test-suite-rnmEEI1K/lib/python3.7/site-packages/hbmqtt/client.py:206: ConnectException
-------------------------------------------------------------------------------- Captured log call ---------------------------------------------------------------------------------
handler.py                 453 WARNING  Unhandled exception: 'NoneType' object has no attribute 'write'
client.py                  145 WARNING  Connection failed: AttributeError("'NoneType' object has no attribute 'write'")
handler.py                 453 WARNING  Unhandled exception: 'NoneType' object has no attribute 'write'
client.py                  203 WARNING  Reconnection attempt failed: AttributeError("'NoneType' object has no attribute 'write'")
handler.py                 453 WARNING  Unhandled exception: 'NoneType' object has no attribute 'write'
client.py                  203 WARNING  Reconnection attempt failed: AttributeError("'NoneType' object has no attribute 'write'")
handler.py                 453 WARNING  Unhandled exception: 'NoneType' object has no attribute 'write'
client.py                  203 WARNING  Reconnection attempt failed: AttributeError("'NoneType' object has no attribute 'write'")
client.py                  205 ERROR    Maximum number of connection attempts reached. Reconnection aborted

It work after provided the protocol, but error message no tips. I am confused by the error message.

C = MQTTClient()
yield from C.connect('mqtts://test.mosquitto.org/')