Hi,
I created a python module with VSCode extension (Azure IoT Edge: New Iot Edge Solution -> Python module) and tried to deploy onto an edge device I have. However, it fails to connect to IoTHub after i deploy with the error below (obtained with "sudo iotedge logs pythonmodule":
IoT Hub Client for Python
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/azure/iot/device/common/mqtt_transport.py", line 395, in connect
host=self._hostname, port=8883, keepalive=self._keep_alive
File "/usr/local/lib/python3.7/site-packages/paho/mqtt/client.py", line 941, in connect
return self.reconnect()
File "/usr/local/lib/python3.7/site-packages/paho/mqtt/client.py", line 1075, in reconnect
sock = self._create_socket_connection()
File "/usr/local/lib/python3.7/site-packages/paho/mqtt/client.py", line 3546, in _create_socket_connection
return socket.create_connection(addr, source_address=source, timeout=self._keepalive)
File "/usr/local/lib/python3.7/socket.py", line 728, in create_connection
raise err
File "/usr/local/lib/python3.7/socket.py", line 716, in create_connection
sock.connect(sa)
socket.timeout: timed out
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/azure/iot/device/iothub/aio/async_clients.py", line 33, in handle_result
return await callback.completion()
File "/usr/local/lib/python3.7/site-packages/azure/iot/device/common/async_adapter.py", line 94, in completion
return await self.future
File "/usr/local/lib/python3.7/site-packages/azure/iot/device/common/pipeline/pipeline_stages_mqtt.py", line 193, in _run_op
self.transport.connect(password=password)
File "/usr/local/lib/python3.7/site-packages/azure/iot/device/common/mqtt_transport.py", line 417, in connect
raise exceptions.ConnectionFailedError(cause=e)
azure.iot.device.common.transport_exceptions.ConnectionFailedError: ConnectionFailedError(None) caused by timeout('timed out')
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "./main.py", line 71, in <module>
loop.run_until_complete(main())
File "/usr/local/lib/python3.7/asyncio/base_events.py", line 587, in run_until_complete
return future.result()
File "./main.py", line 23, in main
await module_client.connect()
File "/usr/local/lib/python3.7/site-packages/azure/iot/device/aio/patch_documentation.py", line 146, in connect
return await super(IoTHubModuleClient_, self).connect()
File "/usr/local/lib/python3.7/site-packages/azure/iot/device/iothub/aio/async_clients.py", line 187, in connect
await handle_result(callback)
File "/usr/local/lib/python3.7/site-packages/azure/iot/device/iothub/aio/async_clients.py", line 37, in handle_result
raise exceptions.ConnectionFailedError(message="Could not connect to IoTHub", cause=e)
azure.iot.device.exceptions.ConnectionFailedError: ConnectionFailedError('Could not connect to IoTHub') caused by ConnectionFailedError(None)
Unexpected error ConnectionFailedError('Could not connect to IoTHub') caused by ConnectionFailedError(None)
The code I used is the default code created with Azure IoT Extension on VSCode:
module_client = IoTHubModuleClient.create_from_edge_environment()
await module_client.connect()
What should I do to make it work?