파이썬을 통해 azure iot hub에서 메시지 수신 오류

solution-lab 0 평판 포인트
2024-05-10T02:06:10.41+00:00
from azure.iot.device import IoTHubDeviceClient, Message
import threading
import time

CONNECTION_STRING = "HostName=ID.azure-devices.net;DeviceId=sample;SharedAccessKey=???"

def message_handler(message):
    print("Received message from Azure IoT Hub:")
    print(message.data.decode("utf-8"))
    print("")

def main():
    client = IoTHubDeviceClient.create_from_connection_string(CONNECTION_STRING)
    client.connect()

    # 메시지 핸들러 설정
    client.on_message_received = message_handler

    try:
        # 메인 스레드가 종료되지 않도록 유지
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        print("IoTHubDeviceClient sample stopped")

if __name__ == "__main__":
    main()

오류 메시지는 다음과 같습니다 .

Exception caught in background thread. Unable to handle.

['azure.iot.device.common.transport_exceptions.ConnectionDroppedError: Unexpected disconnection\n']

코드가 잘못되었거나, 추가적인 방법이 있나요?

Exchange Server
Exchange Server
Microsoft 클라이언트/서버 메시징 및 공동 작업 소프트웨어 제품군.
질문 4개
Windows 10
Windows 10
개인용 컴퓨터 및 태블릿에서 실행되는 Microsoft 운영 체제입니다.
질문 63개
Windows Server
Windows Server
엔터프라이즈 수준 관리, 데이터 스토리지, 애플리케이션 및 통신을 지원하는 Microsoft 서버 운영 체제 제품군입니다.
질문 22개
Microsoft Q&A
Microsoft Q&A
이 태그를 사용하여 제안, 기능 요청 및 버그를 Microsoft Q&A 팀과 공유합니다. Microsoft Q&A 팀은 정기적으로 피드백을 평가하고 그 과정에서 업데이트를 제공합니다.
질문 105개
댓글 0개 설명 없음
투표 {count}개