A Python SDK for connecting devices to Microsoft Azure IoT services

Overview

V2 - We are now GA!

Build Status

This repository contains code for the Azure IoT SDKs for Python. This enables python developers to easily create IoT device solutions that seamlessly connect to the Azure IoT Hub ecosystem.

If you're looking for the v1.x.x client library, it is now preserved in the v1-deprecated branch.

Azure IoT SDK for Python

This repository contains the following libraries:

Critical Upcoming Change Notice

All Azure IoT SDK users are advised to be aware of upcoming TLS certificate changes for Azure IoT Hub and Device Provisioning Service that will impact the SDK's ability to connect to these services. In October 2022, both services will migrate from the current Baltimore CyberTrust CA Root to the DigiCert Global G2 CA root. There will be a transition period beforehand where your IoT devices must have both the Baltimore and Digicert public certificates installed in their certificate store in order to prevent connectivity issues.

Devices with only the Baltimore public certificate installed will lose the ability to connect to Azure IoT hub and Device Provisioning Service in October 2022.

To prepare for this change, make sure your device's certificate store has both of these public certificates installed.

For a more in depth explanation as to why the IoT services are doing this, please see this article.

Installing the libraries

Pip installs are provided for all of the SDK libraries in this repo:

Device libraries

IoTHub library

Using the libraries

Want to start off on the right foot? Be sure to learn about common pitfalls of using this Python SDK before starting a project.

You can also view samples in each library:

Features

✔️ feature available ✖️ feature planned but not yet supported no support planned*

*Features that are not planned may be prioritized in a future release, but are not currently planned

This SDK only supports the MQTT protocol.

Device Client Library (azure-iot-device)

IoTHub Device Client

Features Status Description
Authentication ✔️ Connect your device to IoT Hub securely with supported authentication, including symmetric key, X-509 Self Signed, Certificate Authority (CA) Signed, and SASToken
Send device-to-cloud message ✔️ Send device-to-cloud messages (max 256KB) to IoT Hub with the option to add custom properties.
Receive cloud-to-device messages ✔️ Receive cloud-to-device messages and read associated custom and system properties from IoT Hub, with the option to complete/reject/abandon C2D messages.
Device Twins ✔️ IoT Hub persists a device twin for each device that you connect to IoT Hub. The device can perform operations like get twin tags, subscribe to desired properties.
Direct Methods ✔️ IoT Hub gives you the ability to invoke direct methods on devices from the cloud. The SDK supports handler for method specific and generic operation.
Connection Status and Error reporting ✖️ Error reporting for IoT Hub supported error code. *This SDK supports error reporting on authentication and Device Not Found.
Retry policies ✔️ Operations which fail with a transient error and dropped connections will be retried with a fixed 10 second interval by default. This functionality can be disabled if desired, and the interval can be configured
Upload file to Blob ✔️ A device can initiate a file upload and notifies IoT Hub when the upload is complete.

IoTHub Module Client

Note: IoT Edge for Python is scoped to Linux containers & devices only. Learn more about using Linux containers for IoT edge on Windows devices.

Features Status Description
Authentication ✔️ Connect your device to IoT Hub securely with supported authentication, including symmetric key, X-509 Self Signed, and Certificate Authority (CA) Signed. SASToken authentication is not currently supported.
Send device-to-cloud message ✔️ Send device-to-cloud messages (max 256KB) to IoT Hub with the option to add custom properties.
Receive cloud-to-device messages ✔️ Receive cloud-to-device messages and read associated custom and system properties from IoT Hub, with the option to complete/reject/abandon C2D messages.
Device Twins ✔️ IoT Hub persists a device twin for each device that you connect to IoT Hub. The device can perform operations like get twin tags, subscribe to desired properties.
Direct Methods ✔️ IoT Hub gives you the ability to invoke direct methods on devices from the cloud. The SDK supports handler for method specific and generic operation.
Connection Status and Error reporting ✖️ Error reporting for IoT Hub supported error code. *This SDK supports error reporting on authentication and Device Not Found.
Retry policies ✔️ Operations which fail with a transient error and dropped connections will be retried with a fixed 10 second interval. TThis functionality can be disabled if desired, and the interval can be configured
Direct Invocation of Method on Modules ✔️ Invoke method calls to another module using using the Edge Gateway.

Provisioning Device Client

Features Status Description
TPM Individual Enrollment Provisioning via Trusted Platform Module.
X.509 Individual Enrollment ✔️ Provisioning via X.509 root certificate. Please review the samples folder and this quickstart on how to create a device client.
X.509 Enrollment Group ✔️ Provisioning via X.509 leaf certificate). Please review the samples folder on how to create a device client.
Symmetric Key Enrollment ✔️ Provisioning via Symmetric key attestation). Please review the samples folder on how to create a device client.

IoTHub Service Library (azure-iot-hub)

Registry Manager

Features Status Description
Identity registry (CRUD) ✔️ Use your backend app to perform CRUD operation for individual device or in bulk.
Cloud-to-device messaging ✔️ Use your backend app to send cloud-to-device messages, and set up cloud-to-device message receivers.
Direct Methods operations ✔️ Use your backend app to invoke direct method on device.
Device Twins operations ✔️ Use your backend app to perform device twin operations. *Twin reported property update callback and replace twin are in progress.
Query ✔️ Use your backend app to perform query for information.
Jobs ✖️ Use your backend app to perform job operation.

IoTHub Provisioning Service Library

Feature is Coming Soon

Features Status Description
CRUD Operation with TPM Individual Enrollment ✖️ Manage device enrollment using TPM with the service SDK.
Bulk CRUD Operation with TPM Individual Enrollment ✖️ Bulk manage device enrollment using TPM with the service SDK.
CRUD Operation with X.509 Individual Enrollment ✖️ Manages device enrollment using X.509 individual enrollment with the service SDK.
CRUD Operation with X.509 Group Enrollment ✖️ Manages device enrollment using X.509 group enrollment with the service SDK.
Query enrollments ✖️ Query registration states with the service SDK.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Comments
  • GPS python send message to Azure iot from Linux device

    GPS python send message to Azure iot from Linux device

    Hi guys, from Linux with python I can send messages to Iot Azure with the code below, but could you also extend on how to pass with it GPS, please?

    import os
        import asyncio
        from azure.iot.device.aio import IoTHubDeviceClient
    etc
    

    from simple_send_message from python azure sdk

    simple_send_message.py
    Sending message...
    Message successfully sent!
    
    
    enhancement IoTSDK waiting-on-reply 
    opened by AndreV84 62
  • [Technical Question]How do I handle azure.iot.device send_message hanging when message quota is exhausted

    [Technical Question]How do I handle azure.iot.device send_message hanging when message quota is exhausted

    I have a project on raspberry pi that sends telemetry data to azure hub. An issue I am coming up against is when I have exceeded by daily quota of messages being sent from my device to cloud, the following line hangs.

    await client.send_message(message)

    I am trying to get over this by using asyncio.wait_for, and setting a timeout of 2 secs, so that my code will not wait indefinitely to return from the send_message() method.

    My code does timeout after the specified time, but I get another error that Im not sure how to deal with.

    The code Im using is below...

    from azure.iot.device.aio import IoTHubDeviceClient
    from azure.iot.device import Message
    import time
    import asyncio
    from datetime import datetime
    
        
    async def SendMessage(clientPairingId,clientDeviceId,type,subType,deviceState,pairingSetpoint=None):
    
            
    
        messageTemplate = """{{"iotDeviceId":"{iotDeviceId}","timeStampUTC":"{timeStampUTC}","clientPairingId":"{clientPairingId}","clientDeviceId":"{clientDeviceId}","type":"{type}","subType":"{subType}","state": "{deviceState}","setPoint": "{pairingSetpoint}"}}"""        
        connectionString="**********"
        client = IoTHubDeviceClient.create_from_connection_string(connectionString)
        
        await client.connect()
        
        message = Message(messageTemplate.format(iotDeviceId="xx1",
                                                clientPairingId=clientPairingId,
                                                clientDeviceId=clientDeviceId,
                                                type=type,
                                                subType=subType,
                                                deviceState=deviceState,
                                                pairingSetpoint=pairingSetpoint,
                                                timeStampUTC=datetime.utcnow()))
       
    
        
        
        await client.send_message(message)
        #await asyncio.sleep(300)
        await client.shutdown()
    
    async def main():
        for i in range(1):
            try:
                coros=[SendMessage(clientPairingId="cp1",clientDeviceId="cd1",type="D",subType="ST1",deviceState="On",pairingSetpoint="n/a")]
                
                await asyncio.wait_for(asyncio.gather(*coros),.5)
                
            except asyncio.TimeoutError:
                print("Timed out")
            except asyncio.CancelledError:
                print("Cancelled")
            except Exception as e:
                print(e)
            except:
                print("catch all")
    
    def handle_exception(loop, context):
        msg=context.get("exception",context["message"])
        
    if __name__ == "__main__":
        s = time.perf_counter()
        #asyncio.run(main())
        asyncio.run(main(),debug=False)
        elapsed = time.perf_counter() - s
        print(f"{__file__} executed in {elapsed:0.2f} seconds.")
    

    output ################################################# Timed out _GatheringFuture exception was never retrieved future: <_GatheringFuture finished exception=ClientError('Unexpected failure')> Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/azure/iot/device/iothub/aio/async_clients.py", line 33, in handle_result return await callback.completion() File "/usr/local/lib/python3.7/dist-packages/azure/iot/device/common/async_adapter.py", line 94, in completion return await self.future concurrent.futures._base.CancelledError

    The above exception was the direct cause of the following exception:

    Traceback (most recent call last): File "/home/pi/CabinetFarming/WIP/POC_SimpleAzureSendMessageMock.py", line 30, in SendMessage await client.send_message(message) File "/usr/local/lib/python3.7/dist-packages/azure/iot/device/aio/patch_documentation.py", line 60, in send_message return await super(IoTHubDeviceClient_, self).send_message(message) File "/usr/local/lib/python3.7/dist-packages/azure/iot/device/iothub/aio/async_clients.py", line 301, in send_message await handle_result(callback) File "/usr/local/lib/python3.7/dist-packages/azure/iot/device/iothub/aio/async_clients.py", line 53, in handle_result raise exceptions.ClientError(message="Unexpected failure", cause=e) azure.iot.device.exceptions.ClientError: ClientError('Unexpected failure') caused by CancelledError() POC_SimpleAzureSendMessageMock.py executed in 0.51 seconds.

    question investigation-required fix-checked-in IoTSDK waiting-on-reply 
    opened by terryholland 34
  • ConnectionFailedError(None) caused by gaierror(-3, 'Temporary failure in name resolution')

    ConnectionFailedError(None) caused by gaierror(-3, 'Temporary failure in name resolution')

    Hi i am having this problem, this is for azure-iot-device 2.1.0

    Any ideas? thanks in advance

    ERROR:azure.iot.device.common.pipeline.pipeline_stages_mqtt:transport.connect raised error
    02.03.20 14:34:40 (-0700)  core  ERROR:azure.iot.device.common.pipeline.pipeline_stages_mqtt:Traceback (most recent call last):
    02.03.20 14:34:40 (-0700)  core    File "/usr/local/lib/python3.7/dist-packages/azure/iot/device/common/mqtt_transport.py", line 367, in connect
    02.03.20 14:34:40 (-0700)  core      host=self._hostname, port=8883, keepalive=DEFAULT_KEEPALIVE
    02.03.20 14:34:40 (-0700)  core    File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 937, in connect
    02.03.20 14:34:40 (-0700)  core      return self.reconnect()
    02.03.20 14:34:40 (-0700)  core    File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 1071, in reconnect
    02.03.20 14:34:40 (-0700)  core      sock = self._create_socket_connection()
    02.03.20 14:34:40 (-0700)  core    File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 3522, in _create_socket_connection
    02.03.20 14:34:40 (-0700)  core      return socket.create_connection(addr, source_address=source, timeout=self._keepalive)
    02.03.20 14:34:40 (-0700)  core    File "/usr/lib/python3.7/socket.py", line 707, in create_connection
    02.03.20 14:34:40 (-0700)  core      for res in getaddrinfo(host, port, 0, SOCK_STREAM):
    02.03.20 14:34:40 (-0700)  core    File "/usr/lib/python3.7/socket.py", line 748, in getaddrinfo
    02.03.20 14:34:40 (-0700)  core      for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
    02.03.20 14:34:40 (-0700)  core  socket.gaierror: [Errno -3] Temporary failure in name resolution
    02.03.20 14:34:40 (-0700)  core  
    02.03.20 14:34:40 (-0700)  core  The above exception was the direct cause of the following exception:
    02.03.20 14:34:40 (-0700)  core  
    02.03.20 14:34:40 (-0700)  core  Traceback (most recent call last):
    02.03.20 14:34:40 (-0700)  core    File "/usr/local/lib/python3.7/dist-packages/azure/iot/device/common/pipeline/pipeline_stages_mqtt.py", line 117, in _run_op
    02.03.20 14:34:40 (-0700)  core      self.transport.connect(password=self.sas_token)
    02.03.20 14:34:40 (-0700)  core    File "/usr/local/lib/python3.7/dist-packages/azure/iot/device/common/mqtt_transport.py", line 387, in connect
    02.03.20 14:34:40 (-0700)  core      raise exceptions.ConnectionFailedError(cause=e)
    02.03.20 14:34:40 (-0700)  core  azure.iot.device.common.transport_exceptions.ConnectionFailedError: ConnectionFailedError(None) caused by gaierror(-3, 'Temporary failure in name resolution')
    02.03.20 14:34:40 (-0700)  core  
    02.03.20 14:34:40 (-0700)  core  ERROR:azure.iot.device.common.pipeline.pipeline_ops_base:ConnectOperation: completing with error ConnectionFailedError(None) caused by gaierror(-3, 'Temporary failure in name resolution')
    02.03.20 14:34:40 (-0700)  core  ERROR:azure.iot.device.common.pipeline.pipeline_stages_base:ConnectionLockStage(ConnectOperation): op failed.  Unblocking queue with error: ConnectionFailedError(None) caused by gaierror(-3, 'Temporary failure in name resolution')
    02.03.20 14:34:40 (-0700)  core  ERROR:azure.iot.device.common.pipeline.pipeline_ops_base:ConnectOperation: completing with error ConnectionFailedError(None) caused by gaierror(-3, 'Temporary failure in name resolution')
    02.03.20 14:34:40 (-0700)  core  ERROR:azure.iot.device.common.async_adapter:Callback completed with error ConnectionFailedError(None) caused by gaierror(-3, 'Temporary failure in name resolution')
    02.03.20 14:34:40 (-0700)  core  ERROR:azure.iot.device.common.async_adapter:["azure.iot.device.common.transport_exceptions.ConnectionFailedError: ConnectionFailedError(None) caused by gaierror(-3, 'Temporary failure in name resolution')\n"]
    

    AB#7366699

    investigation-required IoTSDK 
    opened by MiguelCHR 34
  • ImportError: libboost_python-py27.so.1.55.0: cannot open shared object file: No such file or directory on raspbian

    ImportError: libboost_python-py27.so.1.55.0: cannot open shared object file: No such file or directory on raspbian

    • OS and version used: Linux raspberrypi 4.9.80-v7+ #1098 SMP Fri Mar 9 19:11:42 GMT 2018 armv7l GNU/Linux

    • Python runtime used: Python 2.7.13 and Python 3.5.3

    • SDK version used: 1.3.0

    Description of the issue:

    import iothub_client fails with the error message seen below

    Code sample exhibiting the issue:

    import iothub_client

    Console log of the issue:

    Traceback (most recent call last): File "app.py", line 4, in import iothub_client File "/home/pi/.local/lib/python2.7/site-packages/iothub_client/init.py"line 1, in from .iothub_client import * ImportError: libboost_python-py27.so.1.55.0: cannot open shared object file: Nsuch file or directory

    enhancement raspbian 
    opened by eifinger 32
  • Error showing from .iothub_client import *

    Error showing from .iothub_client import *

    Operating System: Windows 10 Language : Python Version: Python 3.7

    I was going through the tutorial given on Azure Portal's IoT Hub for sending telemetry. I am following the python tutorial https://docs.microsoft.com/en-us/azure/iot-hub/quickstart-send-telemetry-python .

    azure python tutorial

    I followed the steps given exactly in the tutorial. The sample code to be executed was also given https://github.com/Azure-Samples/azure-iot-samples-python/archive/master.zip

    When i run the SimulatedDevice.py in the folder simulated-device code i get the following error

    error

    I also tried the suggestions given on net. I created an anaconda environment in python 3.6 and python 2.7 . But the same error persists. Can someone help with the above issue?

    question 
    opened by kiran007francis 29
  • Disconnect without reconnect in rc13

    Disconnect without reconnect in rc13

    Up until v2.0rc12 I sometimes had the issue with the (spurious) OutOfMemory error related to connection problems. Since updating to rc13 last week, I did not find those issues anymore, but instead had the following:

    02:09:14|pipeline| ERROR |pipeline_stages:_on_mqtt_discon | MQTTTransportStage: _on_mqtt_disconnect called: Paho returned rc==1 caused by None
    02:09:14|pipeline| WARNI |pipeline_stages:_on_mqtt_discon | MQTTTransportStage: disconnection was unexpected
    02:09:14|pipeline| ERROR |handle_exceptio:handle_backgrou | Exception caught in background thread.  Unable to handle.
    02:09:14|pipeline| ERROR |handle_exceptio:handle_backgrou | ['azure.iot.device.common.transport_exceptions.ConnectionDroppedError: None caused by Paho returned rc==1 caused by None\n']
    

    From then on, the connection seemed to be dead with no more messages being sent. Should this exception be handled by the user (me) or should the reconnect be done by the SDK?

    investigation-required IoTSDK 
    opened by oerpli 28
  • Get

    Get "iotHubName is not found" error when using Pip packages

    • OS and version used: Windows 10

    • Python runtime used: Python 3.6.5

    • SDK version used: azure-iothub-device-client-1.4.0

    Description of the issue:

    When sending message to Azure IoT Hub using packages installed by Pip then get "iotHubName is not found" error.

    Code sample exhibiting the issue:

    I run the official sample:iothub_client_sample.py

    Console log of the issue:

    D:\Sample\azure-iot-sdk-python\device\samples>python iothub_client_sample.py -c "HostName=xxxxxx.azure-devices.net;DeviceId=device1;SharedAccessKey=xxxxxx" -p mqtt
    
    Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)]
    IoT Hub Client for Python
    Starting the IoT Hub Python sample...
        Protocol MQTT
        Connection string=HostName=ritaiothub.azure-devices.net;DeviceId=device1;SharedAccessKey=***
    Error: Time:Mon Jul 16 17:07:45 2018 File:C:\release\iot-sdks-internals\release\python\automation\aziotsdk_pytools\src\c\iothub_client\src\iothub_client_core_ll.c Func:IoTHubClientCore_LL_CreateFromConnectionString Line:892 iotHubName is not found
    Error: Time:Mon Jul 16 17:07:45 2018 File:C:\release\iot-sdks-internals\release\python\automation\aziotsdk_pytools\src\c\iothub_client\src\iothub_client_core.c Func:create_iothub_instance Line:928 Failure creating iothub handle
    set_option TrustedCerts successful
    SetRetryPolicy to: retryPolicy = 2
    SetRetryPolicy to: retryTimeoutLimitInSeconds = 100
    GetRetryPolicy returned: retryPolicy = 2
    GetRetryPolicy returned: retryTimeoutLimitInSeconds = 100
    IoTHubClient is reporting state
    IoTHubClient sending 5 messages
    IoTHubClient.send_event_async accepted message [0] for transmission to IoT Hub.
    IoTHubClient.send_event_async accepted message [1] for transmission to IoT Hub.
    IoTHubClient.send_event_async accepted message [2] for transmission to IoT Hub.
    IoTHubClient.send_event_async accepted message [3] for transmission to IoT Hub.
    IoTHubClient.send_event_async accepted message [4] for transmission to IoT Hub.
    IoTHubClient waiting for commands, press Ctrl-C to exit
    Send status: BUSY
    Confirmation[0] for reported state received with:
        status_code: 204
        Total calls confirmed: 1
    Confirmation[0] received for message with result = OK
        message_id: message_0
        correlation_id: correlation_0
        Properties: {'temperatureAlert': 'false'}
        Total calls confirmed: 1
    Confirmation[1] received for message with result = OK
        message_id: message_1
        correlation_id: correlation_1
        Properties: {'temperatureAlert': 'false'}
        Total calls confirmed: 2
    Confirmation[2] received for message with result = OK
        message_id: message_2
        correlation_id: correlation_2
        Properties: {'temperatureAlert': 'true'}
        Total calls confirmed: 3
    Confirmation[3] received for message with result = OK
        message_id: message_3
        correlation_id: correlation_3
        Properties: {'temperatureAlert': 'true'}
        Total calls confirmed: 4
    Confirmation[4] received for message with result = OK
        message_id: message_4
        correlation_id: correlation_4
        Properties: {'temperatureAlert': 'false'}
        Total calls confirmed: 5
    
    fix-checked-in 
    opened by luyaok 28
  • Client disconnects - and does not reconnect back , the caller of the thread does not connect back (though explicitly mentioned)

    Client disconnects - and does not reconnect back , the caller of the thread does not connect back (though explicitly mentioned)

    Context

    • OS and version used: Ubuntu 18.04
    • Python version: Python 3.6.9.
    • pip version: pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)
    • list of installed packages: azure-core==1.23.1 azure-iot-device==2.11.0 azure-storage-blob==12.9.0

    Description of the issue

    Randomly I used to receive the below exception and it stucks there and client connectivity does not recover when I try to send message to IoTHub.

    {/src/helpers/iothubOperations.py} 217] - Attempting to send message Apr 20 01:01:49 x86-000079 b8957f22f164[591]: [2022-04-20 01:01:49,072 W {/usr/local/lib/python3.6/dist-packages/azure/iot/device/common/pipeline/pipeline_stages_base.py} 130] - ReconnectStage: DisconnectEvent received while in unexpected state - DISCONNECTED, Connected: False Apr 20 01:01:49 x86-000079 b8957f22f164[591]: [2022-04-20 01:01:49,078 E {/usr/local/lib/python3.6/dist-packages/azure/iot/device/common/handle_exceptions.py} 28] - Exception caught in background thread. Unable to handle. Apr 20 01:01:49 x86-000079 b8957f22f164[591]: [2022-04-20 01:01:49,078 E {/usr/local/lib/python3.6/dist-packages/azure/iot/device/common/handle_exceptions.py} 29] - ['azure.iot.device.common.transport_exceptions.ConnectionDroppedError: Unexpected disconnection\n'] Apr 20 01:01:49 x86-000079 b8957f22f164[591]: [2022-04-20 01:01:49,078 E {/usr/local/lib/python3.6/dist-packages/azure/iot/device/common/handle_exceptions.py} 28] - Exception caught in background thread. Unable to handle. Apr 20 01:01:49 x86-000079 b8957f22f164[591]: [2022-04-20 01:01:49,080 E {/usr/local/lib/python3.6/dist-packages/azure/iot/device/common/handle_exceptions.py} 29] - ['azure.iot.device.common.transport_exceptions.ConnectionDroppedError: Unexpected disconnection\n'] Apr 20 01:01:59 x86-000079 b8957f22f164[591]: [2022-04-20 01:01:59,158 E {/usr/local/lib/python3.6/dist-packages/azure/iot/device/common/handle_exceptions.py} 28] - Exception caught in background thread. Unable to handle. Apr 20 01:01:59 x86-000079 b8957f22f164[591]: [2022-04-20 01:01:59,158 E {/usr/local/lib/python3.6/dist-packages/azure/iot/device/common/handle_exceptions.py} 29] - ['azure.iot.device.common.transport_exceptions.ConnectionFailedError\n'] Apr 20 01:02:19 x86-000079 b8957f22f164[591]: [2022-04-20 01:02:19,196 E {/usr/local/lib/python3.6/dist-packages/azure/iot/device/common/handle_exceptions.py} 28] - Exception caught in background thread. Unable to handle. Apr 20 01:02:19 x86-000079 b8957f22f164[591]: [2022-04-20 01:02:19,196 E {/usr/local/lib/python3.6/dist-packages/azure/iot/device/common/handle_exceptions.py} 29] - ['azure.iot.device.common.transport_exceptions.ConnectionFailedError\n']

    I read in one of the issue (https://github.com/Azure/azure-iot-sdk-python/issues/399) the solution for this is to use connect explicit instead of using existing reconnect within SDK. - but the issue is still occurring with this error message

    {/usr/local/lib/python3.6/dist-packages/azure/iot/device/common/handle_exceptions.py} 28] - Exception caught in background thread. Unable to handle. Apr 20 09:29:44 x86-000079 b8957f22f164[591]: [2022-04-20 09:29:44,150 E {/usr/local/lib/python3.6/dist-packages/azure/iot/device/common/handle_exceptions.py} 29] - ['azure.iot.device.common.transport_exceptions.ConnectionDroppedError: Unexpected disconnection\n'] Apr 20 09:29:44 x86-000079 b8957f22f164[591]: [2022-04-20 09:29:44,771 E {/usr/local/lib/python3.6/dist-packages/azure/iot/device/common/handle_exceptions.py} 28] - Exception caught in background thread. Unable to handle. Apr 20 09:29:44 x86-000079 b8957f22f164[591]: [2022-04-20 09:29:44,771 E {/usr/local/lib/python3.6/dist-packages/azure/iot/device/common/handle_exceptions.py} 29] - ['azure.iot.device.common.transport_exceptions.TlsExchangeAuthError\n']

    Code sample exhibiting the issue

    from azure.iot.device.aio import IoTHubDeviceClient ##creating client self.client= IoTHubDeviceClient.create_from_connection_string( self.cfg_model.conn_string, websockets=True)

    async def iothub_lib_send_message(self, message):
        success = False
        try:
            await self.client.connect()
            await self.client.send_message(message)
    
            success = True
        except Exception as e:
            LOG.debug(f"Failed with exception {e} while sending message to IOT hub")
    
        finally:
            return success
    

    ##caller to this as

                send_msg_loop = asyncio.new_event_loop()
                asyncio.set_event_loop(send_msg_loop)
                msg_send_status = send_msg_loop.run_until_complete(self.iothub_lib_send_message(message))
                send_msg_loop.close()
    

    Console log of the issue

    {/usr/local/lib/python3.6/dist-packages/azure/iot/device/common/handle_exceptions.py} 28] - Exception caught in background thread. Unable to handle. Apr 20 09:29:44 x86-000079 b8957f22f164[591]: [2022-04-20 09:29:44,150 E {/usr/local/lib/python3.6/dist-packages/azure/iot/device/common/handle_exceptions.py} 29] - ['azure.iot.device.common.transport_exceptions.ConnectionDroppedError: Unexpected disconnection\n'] Apr 20 09:29:44 x86-000079 b8957f22f164[591]: [2022-04-20 09:29:44,771 E {/usr/local/lib/python3.6/dist-packages/azure/iot/device/common/handle_exceptions.py} 28] - Exception caught in background thread. Unable to handle. Apr 20 09:29:44 x86-000079 b8957f22f164[591]: [2022-04-20 09:29:44,771 E {/usr/local/lib/python3.6/dist-packages/azure/iot/device/common/handle_exceptions.py} 29] - ['azure.iot.device.common.transport_exceptions.TlsExchangeAuthError\n']

    bug investigation-required IoTSDK waiting-on-reply 
    opened by SURAJTHEGREAT 27
  • Using SDK fails with error: ImportError: libboost_python-py34.so.1.54.0: cannot open shared object file: No such file or directory

    Using SDK fails with error: ImportError: libboost_python-py34.so.1.54.0: cannot open shared object file: No such file or directory

    • OS and version used: Debian GNU/Linux 8 (jessie) in a Docker container based off of python:3-slim image

    • Python runtime used: Python 3.6.3

    • SDK version used: azure-iothub-device-client (1.1.25.0) azure-iothub-service-client (1.1.0.17)

    Description of the issue:

    Installation was performed based off of the above environment as: apt-get install libpython3-dev apt-get install libboost-python-dev pip3 install azure-iothub-device-client==1.1.25.0 pip3 install azure-iothub-service-client==1.1.0.17

    Once after that, using either the device SDK or service SDK by importing in Python it fails with error: ImportError: libboost_python-py34.so.1.54.0: cannot open shared object file: No such file or directory

    Effectively cannot use Python SDK.

    Code sample exhibiting the issue:

    from iothub_service_client import IoTHubRegistryManager, IoTHubRegistryManagerAuthMethod or from iothub_client import IoTHubMessageDispositionResult

    Console log of the issue:

    From the Python console:

    from iothub_client import IoTHubMessageDispositionResult Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.6/site-packages/iothub_client/init.py", line 1, in from .iothub_client import * ImportError: libboost_python-py34.so.1.54.0: cannot open shared object file: No such file or directory

    investigation-required 
    opened by srids 27
  • fix(azure-iot-device): Fix flaky HandlerManager tests

    fix(azure-iot-device): Fix flaky HandlerManager tests

    • Fixed bugs in tests due to MagicMocks not being threadsafe
    • Optimized tests for better performance

    This PR has passed 10 consecutive full pipeline runs with no errors, as well as 1000 consecutive runs on a local machine

    opened by cartertinney 26
  • Error in sample from Windows

    Error in sample from Windows

    • OS and version used: Windows 10

    • Python runtime used: Python 3.4.3

    • SDK version used: azure-iothub-device-client 1.1.16.0

    Description of the issue:

    I installed successfully through pip the azure-iothub-device-client (1.1.16.0) but when I try to import iothub_client (as in the samples given in the project) I get the error below.

    Code sample exhibiting the issue:

    import iothub_client

    Console log of the issue:

    C:\Python34\python.exe C:/[securePath]/main.py Traceback (most recent call last): File "C:/[securePath]/main.py", line 11, in import iothub_client File "C:\Python34\lib\site-packages\iothub_client_init_.py", line 1, in from .iothub_client import * ImportError: DLL load failed: The specified module could not be found.

    Process finished with exit code 1

    opened by Moncefmd 25
  • Sample with items in queue

    Sample with items in queue

    The connect_retry_with_telemetry was already reviewed. Simply transferring it to this branch.

    The other file has been running for 3 days on Windows successfully.

    opened by olivakar 6
  • Feedback requested: Python SDK config and status object for debugging

    Feedback requested: Python SDK config and status object for debugging

    Looking for feedback on mqtt_transport.py changes. Tony and I have been talking about something like this as a way for customers to get a quick status on the health of our library. This is far from complete, but the intention is to provide data for observability/debugging only with the hope of avoiding the need to pour through reams of debug data.

    The config object looks like this;

      "paho_config": {
        "transport": "websockets",
        "protocol": "4",
        "keepalive": 60,
        "connect_timeout": 5.0,
        "reconnect_on_failure": true,
        "reconnect_delay_min": 7200,
        "reconnect_delay_max": 120,
        "host": "bertk.azure-devices.net",
        "port": 443,
        "proxy_args": {},
        "socket_class": "WebsocketWrapper",
        "socket_name": "No socket name"
      },
    

    and the status object looks like this:

      "paho_status": {
        "connect_rc_codes": {
          "0": 2
        },
        "on_connect_rc_codes": {
          "0": 2
        },
        "connect_exceptions": {
          "timeout": 3
        },
        "disconnect_rc_codes": {},
        "on_disconnect_rc_codes": {
          "16": 1,
          "0": 1
        },
        "disconnect_exceptions": {},
        "publish_rc_codes": {
          "0": 631
        },
        "publish_exceptions": {},
        "subscribe_rc_codes": {},
        "subscribe_exceptions": {},
        "unsubscribe_rc_codes": {},
        "unsubscribe_exceptions": {},
        "count_message_received": 0,
        "count_subscribe": 0,
        "count_suback": 0,
        "count_unsubscribe": 0,
        "count_unsuback": 0,
        "count_publish": 631,
        "count_puback": 631,
        "shut_down": false,
        "time_since_last_paho_traffic_in": "0:00:00.779999",
        "time_since_last_paho_traffic_out": "0:00:05.885535",
        "client_object_id": 140285330079296,
        "thread_name": "Thread-14",
        "thread_is_alive": "True",
        "len_out_mesage_queue": 0,
        "len_in_message_queue": 0,
        "len_out_pakcet_queue": 0,
        "thread_terminate": false,
        "paho_connection_state": 1
      },
    
    opened by BertKleewein 0
  • Cannot process direct call with empty payload

    Cannot process direct call with empty payload

    In Azure portal, when issuing a Direct Call to a module, Payload is described as: "Optional data to pass to the method. May be a single value or a JSON object/array." Since it is optional, I assume it may be missing / empty.

    However, issuing such a call to module using Python SDK, results in an exception before control reaches module code:

    WARNING - <azure.iot.device.iothub.pipeline.pipeline_stages_iothub_mqtt.IoTHubMQTTTranslationStage object at 0x7fa98fe6b220>: Unexpected error in ._handle_pipeline_event() call: Expecting value: line 1 column 1 (char 0)

    Using Azure Python SDK 2.12, with python 3.8.

    bug investigation-required IoTSDK 
    opened by Cavaler 0
  • Use DPS with TPM in Python

    Use DPS with TPM in Python

    I would like to ask you if is there any reason why you don't support provisioning with TPM in Python?

    image

    We are working on an IoT solution (30k+ IoT devices). Every device has a TPM. We would like to use Device Provisioning Service to establish a connection with the IoT hub. Because we can use TPM, for us it makes sense to use your DPS solution with TPM. Our main language is Python, we would like to use it for this device application too.

    But I see you don't support provision with TPM in your Python SDK. Is there any reason why you don't support it, please? I'm thinking I would implement it ourselves but maybe there is a problem which I can't see now. I see you supported this case in your previous SDK version.

    Our main problem is, we don't have the device in our hands before the device is delivered to the customer. That means, we can't for example generate and save an X.509 certificate to the device. We have only the public key from TPM.

    I would like to ask you, can you please help us with how to use DPS and TPM together in Python? I would like to avoid to implement the application in different language.

    Thank you.

    enhancement IoTSDK 
    opened by marosrojis 5
Releases(2022-08-23)
Owner
Microsoft Azure
APIs, SDKs and open source projects from Microsoft Azure
Microsoft Azure
Enables you to execute scripts and perform API requests in MikroTik router

HomeAssistant component: MikroTik API The mikrotik_api platform enables you to execute scripts and perform API requests in MikroTik router To enable M

Pavel S 6 Aug 12, 2022
Python script to decode the EU Covid-19 vaccine certificate

vacdec Python script to decode the EU Covid-19 vaccine certificate This script takes an image with a QR code of a vaccine certificate as the parameter

Hanno Böck 244 Nov 30, 2022
Python + AWS Lambda Hands OnPython + AWS Lambda Hands On

Python + AWS Lambda Hands On Python Criada em 1990, por Guido Van Rossum. "Bala de prata" (quase). Muito utilizado em: Automatizações - Selenium, Beau

Marcelo Ortiz de Santana 8 Sep 09, 2022
“ Hey there 👋 I'm Daisy „ AI based Advanced Group Management Bot Suit For All Your Needs ❤️.. Source Code of @Daisyxbot

Project still under heavy development Everything will be changed in the release “ Hey there 👋 I'm Daisy „ AI based Advanced telegram Group Management

TeamDaisyX 43 Nov 12, 2022
An all-in-one financial analytics and smart portfolio creator as a Discord bot!

An all-in-one financial analytics bot to help you gain quantitative financial insights. Finn is a Discord Bot that lets you explore the stock market like you've never before!

6 Jan 12, 2022
A multipurpose Telegram Bot writen in Python for mirroring files

Deepak Clouds Mirror Deepak Clouds Torrent is a multipurpose Telegram Bot writen in Python for mirroring files on the Internet to our beloved Google D

MR.SHAGGY 0 Dec 19, 2021
It was increasingly cumbersome to eye-grep CF output in the AWS console.

cfplot Overview It was increasingly cumbersome to eye-grep CF output in the AWS console. I couldn't find another tool out there to provide individual

46 Dec 26, 2022
Sakamata-alpha-pycord - Sakamata bot alpha with pycord

sakamatabot このリポジトリは? ホロライブ所属VTuber沙花叉クロヱさんの非公式ファンDiscordサーバー「クロヱ水族館」の運営/管理補助を行う

sushichaaaan 1 May 04, 2022
A script that writes automatic instagram comments under a post

Send automatic messages under a post on instagram Instagram will rate limit you after some time. From there on you can only post 1 comment every 40 se

Maximilian Freitag 3 Apr 28, 2022
This Python script will automate the process of uploading your project to GitHub.

ProjectToGithub This Python script will help you to upload your project to Github without having to type in any commands !!! Quick Start guide First C

Imira Randeniya 1 Sep 11, 2022
Asynchronous multi-platform robot framework written in Python

NoneBot ✨ 跨平台 Python 异步机器人框架 ✨ 文档 · 安装 · 开始使用 · 文档打不开? 简介 NoneBot2 是一个现代、跨平台、可扩展的 Python 聊天机器人框架,它基于 Python 的类型注解和异步特性,能够为你的需求实现提供便捷灵活的支持。

NoneBot 3.1k Jan 04, 2023
Python Proof of Concept for retrieving Now Playing on YouTube Music with TabFS

Youtube Music TabFS Python Proof of Concept for retrieving Now Playing on YouTube Music with TabFS. music_information = get_now_playing() pprint(music

Junho Yeo 41 Nov 06, 2022
Fetch fund data from avanza.se using Python and some web scraping with bs4

Py(A)vanza Fetch fund data from avanza.se using Python and some web scraping with bs4. The default way is to display the data in the terminal, apply -

dunderrrrrr 1 Jan 27, 2022
This repository is used to simplify the process of cloning the SSM documents across the AWS regions.

SSM Cloner Introduction This module is created in order to simplify the process of copying the SSM documents from one region to another regions. As an

6 Jun 04, 2022
Minimal API for the COVID Booking System of the Offices at the UniPD Math Dep

Simple and easy to use python BOT for the COVID registration booking system of the math department @ unipd (torre archimede). This API creates an interface with the official website, with more useful

Guglielmo Camporese 4 Dec 24, 2021
Telegram üzerinden paylaşılan kısa linkleri geçmenin daha hızlı bir yolu

Telegram Url skipper Telegramda paylaşılan kısa linkleri geçmenin daha hızlı bir yolu · Hata Raporla · Öneri Yap İçerik Tablosu Kurulum Kullanım Lisan

WarForPeace 6 Oct 07, 2022
Discord Token Finder - Find half of your target's token with just their ID.

Discord Token Finder - Find half of your target's token with just their ID.

Ttawi 2 Apr 07, 2022
A stack-based systems language that supports structures, functions, expressions, and user-defined operator behaviour

A stack-based systems language that supports structures, functions, expressions, and user-defined operator behaviour. Currently compiles to URCL with plans to add additional formats in the future.

Lucida Dragon 3 Nov 03, 2022
allow windows programs to call dssp/mkdssp command from wsl; rework biopython on windows (PDB -> dssp -> fasta)

dssp-wsl Converting PDB (Protein Data Bank) file format to DSSP file format is required for generating datasets of peptides and their secondary struct

Taine Zhao 1 Feb 23, 2022
Official Python client for the MonkeyLearn API. Build and consume machine learning models for language processing from your Python apps.

MonkeyLearn API for Python Official Python client for the MonkeyLearn API. Build and run machine learning models for language processing from your Pyt

MonkeyLearn 157 Nov 22, 2022