Azure / azure-iot-sdk-python

A Python SDK for connecting devices to Microsoft Azure IoT services
MIT License
422 stars 374 forks source link

Func:create_iothub_instance Line:924 Failure creating iothub handle generic error #170

Closed KundhanSoothsayer closed 4 years ago

KundhanSoothsayer commented 6 years ago

Description of the issue:

I am getting this while error while I am doing the file upload from an IoT device to IoT Hub.

Code sample exhibiting the issue:

import time
import sys
import iothub_client
import os
from iothub_client import IoTHubClient, IoTHubClientError, IoTHubTransportProvider, IoTHubClientResult, IoTHubError

CONNECTION_STRING = "CONNECTION_STRING OF DEVICE FROM IOT HUB"
PROTOCOL = IoTHubTransportProvider.HTTP

PATHTOFILE = "FOLDER PATH"
FILENAME = "CustomerSite1_d20180618.csv"

def blob_upload_conf_callback(result, user_context):
    if str(result) == 'OK':
        print ( "...file uploaded successfully." )
    else:
        print ( "...file upload callback returned: " + str(result) )

def iothub_file_upload_sample_run():
    try:
        print ( "IoT Hub file upload sample, press Ctrl-C to exit" )

        client = IoTHubClient(CONNECTION_STRING, PROTOCOL)

        f = open(PATHTOFILE, "r")
        content = f.read()

        client.upload_blob_async(FILENAME, content, len(content), blob_upload_conf_callback, 0)

        print ( "" )
        print ( "File upload initiated..." )

        while True:
            time.sleep(30)

    except IoTHubError as iothub_error:
        print ( "Unexpected error %s from IoTHub" % iothub_error )
        return
    except KeyboardInterrupt:
        print ( "IoTHubClient sample stopped" )
    except:
        print ( "generic error" )

if __name__ == '__main__':
    print ( "Simulating a file upload using the Azure IoT Hub Device SDK for Python" )
    print ( "    Protocol %s" % PROTOCOL )
    #print ( "    Connection string=%s" % CONNECTION_STRING )

    iothub_file_upload_sample_run()     

Console log of the issue:

(geaddzpy36) C:\GEA\OptiPartner\Code>python Optipartner_Batch_Edge.py
Simulating a file upload using the Azure IoT Hub Device SDK for Python
    Protocol HTTP
IoT Hub file upload sample, press Ctrl-C to exit
Error: Time:Mon Aug 13 02:25:47 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:1077 iotHubName is not found
Error: Time:Mon Aug 13 02:25:47 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:924 Failure creating iothub handle
generic error
pierreca commented 6 years ago

@KundhanSoothsayer thanks for opening this issue. I just ran a quick test to verify on my machine and your code runs fine. The first 2 "Error" lines can be ignored as described in #158

The generic error line is what we should be concerned with - an exception is fired in your last except statement. unfortunately without knowing more about the specific exception, it's hard to help. can you try and set a breakpoint there and see what the error is?

Additional questions:

KundhanSoothsayer commented 6 years ago

I installed Python with Anaconda. I have tried with Package as well, the same error occurs. We expect CSV files to be 15 MB to 25 MB (Currently it is less than 15 MB) The exception is occurring immediately. I hope this information helps. Thanks for the response.

pierreca commented 6 years ago

@KundhanSoothsayer can you remove the try/except instructions and paste the call stack produced when the script crashes?

Obad94 commented 5 years ago

i'm having the same issue .

jebrando commented 4 years ago

With the Python v2 reaching General Availability we are recommending users move away from the v1 SDK. We will be closing the v1 SDK issues whose features are covered by the v2 release. Feel free to open an new issue if you find an issue with the v2 SDK.

Thank you for your patronage

az-iot-builder-01 commented 4 years ago

@KundhanSoothsayer, @Obad94, thank you for your contribution to our open-sourced project! Please help us improve by filling out this 2-minute customer satisfaction survey