azure-iot-sdk-python icon indicating copy to clipboard operation
azure-iot-sdk-python copied to clipboard

Python File Upload to Blob Error

Open ikumar222 opened this issue 3 years ago • 3 comments

Context

  • **macOS Big Sur 11.2.2
  • **Python 3.8.2
  • **pip 22.2.2
  • **azure-storage-blob 12.13.1
  • **azure-iothub-provisioningserviceclient 1.2.0
  • **azure-iot-device 2.11.0
  • **azure-core 1.24.2

Description of the issue

I have copied the code from upload_to_blob.py [azure-iot-sdk-python] (samples/async-hub-scenarios).

I have not been able to get the code to work at all. I have already set a local environment of my connection string. I have been able to successfully use send_message.py from the same folder (async-hub-scenarios) including when I get the connection string from the local environment.

I also already connected the iot hub with a blob storage under File upload setting.

I get the error: {"Message":"ErrorCode:ArgumentInvalid;Requested Host is not supported","ExceptionMessage":"Tracking ID::-TimeStamp:2022-08-08T20:+00:00"} azure.iot.device.exceptions.ClientError: Unexpected failure azure.iot.device.exceptions.ServiceError: HTTP operation returned: 400 ArgumentError(Error: Bad Request)

Code sample exhibiting the issue

The code is copied from upload_to_blob.py on August 8th, 2022. No modifications were made.

Console log of the issue: I've deleted some of the words/numbers.

-MacBook-Air:Python $ python3 testfile.py DEBUG:asyncio:Using selector: KqueueSelector DEBUG:azure.iot.device.common.pipeline.pipeline_thread:Starting run_op in pipeline thread DEBUG:azure.iot.device.common.pipeline.pipeline_thread:Creating pipeline executor DEBUG:azure.iot.device.common.pipeline.pipeline_stages_http:Gateway Hostname not present. Setting Hostname to: .azure-devices.net DEBUG:azure.iot.device.common.pipeline.pipeline_stages_http:HTTPTransportStage(InitializePipelineOperation): got connection args DEBUG:azure.iot.device.common.http_transport:creating a SSL context DEBUG:azure.iot.device.common.pipeline.pipeline_ops_base:InitializePipelineOperation: completing without error DEBUG:azure.iot.device.common.pipeline.pipeline_thread:Starting <azure.iot.device.common.evented_callback.EventedCallback object at 0x> in callback thread DEBUG:azure.iot.device.common.pipeline.pipeline_thread:Creating callback executor DEBUG:azure.iot.device.common.evented_callback:Callback completed with result None DEBUG:azure.iot.device.common.pipeline.pipeline_thread:Starting run_op in pipeline thread DEBUG:azure.iot.device.common.pipeline.pipeline_stages_base:SasTokenStage: Scheduling automatic SAS Token renewal at epoch time: DEBUG:azure.iot.device.common.pipeline.pipeline_stages_mqtt:Gateway Hostname not present. Setting Hostname to: .azure-devices.net DEBUG:azure.iot.device.common.pipeline.pipeline_stages_mqtt:MQTTTransportStage(InitializePipelineOperation): got connection args DEBUG:azure.iot.device.common.mqtt_transport:creating mqtt client INFO:azure.iot.device.common.mqtt_transport:Creating client for connecting using MQTT over TCP DEBUG:azure.iot.device.common.mqtt_transport:creating a SSL context DEBUG:azure.iot.device.common.mqtt_transport:configuring SSL context with default certs DEBUG:azure.iot.device.common.mqtt_transport:Created MQTT protocol client, assigned callbacks DEBUG:azure.iot.device.common.pipeline.pipeline_ops_base:InitializePipelineOperation: completing without error DEBUG:azure.iot.device.common.pipeline.pipeline_thread:Starting <azure.iot.device.common.evented_callback.EventedCallback object at 0x> in callback thread DEBUG:azure.iot.device.common.evented_callback:Callback completed with result None DEBUG:azure.iot.device.iothub.aio.loop_management:Creating new event loop - CLIENT_INTERNAL_LOOP DEBUG:asyncio:Using selector: KqueueSelector INFO:azure.iot.device.iothub.aio.async_clients:Connecting to Hub... DEBUG:azure.iot.device.iothub.pipeline.mqtt_pipeline:Starting ConnectOperation on the pipeline DEBUG:azure.iot.device.common.pipeline.pipeline_thread:Starting run_op in pipeline thread DEBUG:azure.iot.device.common.pipeline.pipeline_stages_base:ReconnectStage(ConnectOperation): State changes DISCONNECTED -> CONNECTING. Sending op down DEBUG:azure.iot.device.common.pipeline.pipeline_stages_base:ConnectionLockStage(ConnectOperation): blocking DEBUG:azure.iot.device.common.pipeline.pipeline_stages_mqtt:MQTTTransportStage(ConnectOperation): connecting DEBUG:azure.iot.device.common.pipeline.pipeline_stages_mqtt:MQTTTransportStage(ConnectOperation): Starting watchdog DEBUG:azure.iot.device.common.mqtt_transport:connecting to mqtt broker INFO:azure.iot.device.common.mqtt_transport:Connect using port 8883 (TCP) DEBUG:paho:Sending CONNECT (u1, p1, wr0, wq0, wf0, c0, k60) client_id=b'' DEBUG:azure.iot.device.common.mqtt_transport:_mqtt_client.connect returned rc=0 DEBUG:paho:Received CONNACK (0, 0) INFO:azure.iot.device.common.mqtt_transport:connected with result code: 0 DEBUG:azure.iot.device.common.pipeline.pipeline_thread:Starting _on_mqtt_connected in pipeline thread INFO:azure.iot.device.common.pipeline.pipeline_stages_mqtt:_on_mqtt_connected called DEBUG:azure.iot.device.common.pipeline.pipeline_stages_base:ReconnectStage(ConnectedEvent): State changes CONNECTING -> CONNECTED. Connection established DEBUG:azure.iot.device.common.pipeline.pipeline_stages_base:PipelineRootStage: ConnectedEvent received. Calling on_connected_handler DEBUG:azure.iot.device.common.pipeline.pipeline_thread:Starting _on_connected in callback thread DEBUG:azure.iot.device.common.pipeline.pipeline_stages_mqtt:MQTTTransportStage: completing connect op DEBUG:azure.iot.device.common.pipeline.pipeline_stages_mqtt:MQTTTransportStage(ConnectOperation): cancelling watchdog DEBUG:azure.iot.device.common.pipeline.pipeline_ops_base:ConnectOperation: completing without error DEBUG:azure.iot.device.common.pipeline.pipeline_stages_base:ConnectionLockStage(ConnectOperation): op succeeded. Unblocking queue DEBUG:azure.iot.device.common.pipeline.pipeline_stages_base:ConnectionLockStage(ConnectOperation): unblocking and releasing queued ops. DEBUG:azure.iot.device.common.pipeline.pipeline_stages_base:ConnectionLockStage(ConnectOperation): processing 0 items in queue for error=None DEBUG:azure.iot.device.common.pipeline.pipeline_thread:Starting on_complete in callback thread INFO:azure.iot.device.iothub.abstract_clients:Connection State - Connected DEBUG:azure.iot.device.common.async_adapter:Callback completed with result None INFO:azure.iot.device.iothub.aio.async_clients:Successfully connected to Hub DEBUG:azure.iot.device.iothub.pipeline.http_pipeline:HTTPPipeline get_storage_info_for_blob called DEBUG:azure.iot.device.common.pipeline.pipeline_thread:Starting run_op in pipeline thread DEBUG:azure.iot.device.iothub.pipeline.pipeline_stages_iothub_http:IoTHubHTTPTranslationStage(GetStorageInfoOperation): Translating Get Storage Info Operation to HTTP. DEBUG:azure.iot.device.common.pipeline.pipeline_stages_http:HTTPTransportStage(HTTPRequestAndResponseOperation): Generating HTTP request and setting callback before completing. DEBUG:azure.iot.device.common.pipeline.pipeline_thread:Starting request in azure_iot_http thread DEBUG:azure.iot.device.common.pipeline.pipeline_thread:Creating azure_iot_http executor INFO:azure.iot.device.common.http_transport:sending https POST request to devices/ /files . DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): azure-devices.net:443 DEBUG:urllib3.connectionpool:https://.azure-devices.net:443 "POST /devices/ /files?api-version=2019-10-01 HTTP/1.1" 400 187 DEBUG:azure.iot.device.common.pipeline.pipeline_thread:Starting on_request_completed in pipeline thread DEBUG:azure.iot.device.common.pipeline.pipeline_stages_http:HTTPTransportStage(HTTPRequestAndResponseOperation): Request completed. Completing op. DEBUG:azure.iot.device.common.pipeline.pipeline_stages_http:HTTP Response Status: 400 DEBUG:azure.iot.device.common.pipeline.pipeline_stages_http:HTTP Response: {"Message":"ErrorCode:ArgumentInvalid;Requested Host is not supported","ExceptionMessage":"Tracking ID::-TimeStamp:2022-08-08T20:+00:00"} DEBUG:azure.iot.device.common.pipeline.pipeline_ops_base:HTTPRequestAndResponseOperation: completing without error DEBUG:azure.iot.device.iothub.pipeline.pipeline_stages_iothub_http:IoTHubHTTPTranslationStage(HTTPRequestAndResponseOperation): Got response for GetStorageInfoOperation DEBUG:azure.iot.device.common.pipeline.pipeline_ops_base:GetStorageInfoOperation: completing with error HTTP operation returned: 400 ArgumentError(Error: Bad Request) DEBUG:azure.iot.device.common.pipeline.pipeline_thread:Starting on_complete in callback thread INFO:azure.iot.device.common.async_adapter:Callback completed with error HTTP operation returned: 400 ArgumentError(Error: Bad Request) INFO:azure.iot.device.common.async_adapter:['azure.iot.device.exceptions.ServiceError: HTTP operation returned: 400 ArgumentError(Error: Bad Request)\n'] Traceback (most recent call last): File "/Users//Downloads/azure-iot-sdk-python-2022-03-24/azure-iot-device/azure/iot/device/iothub/aio/async_clients.py", line 33, in handle_result return await callback.completion() File "/Users/ /Downloads/azure-iot-sdk-python-2022-03-24/azure-iot-device/azure/iot/device/common/async_adapter.py", line 91, in completion return await self.future azure.iot.device.exceptions.ServiceError: HTTP operation returned: 400 ArgumentError(Error: Bad Request)

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

Traceback (most recent call last): File "testfile.py", line 127, in asyncio.run(main()) File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/asyncio/runners.py", line 43, in run return loop.run_until_complete(main) File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete return future.result() File "testfile.py", line 87, in main storage_info = await device_client.get_storage_info_for_blob(blob_name) File "/Users/ /Downloads/azure-iot-sdk-python-2022-03-24/azure-iot-device/azure/iot/device/iothub/aio/async_clients.py", line 571, in get_storage_info_for_blob storage_info = await handle_result(callback) File "/Users/ /Downloads/azure-iot-sdk-python-2022-03-24/azure-iot-device/azure/iot/device/iothub/aio/async_clients.py", line 57, in handle_result raise exceptions.ClientError("Unexpected failure") from e azure.iot.device.exceptions.ClientError: Unexpected failure

ikumar222 avatar Aug 08 '22 20:08 ikumar222

I'm not to familiar with specfic python sdk error logs but it looks like: DEBUG:urllib3.connectionpool:https://.azure-devices.net:443 "POST /devices/ /files?api-version=2019-10-01 HTTP/1.1" 400 187

is missing the host name.

anthonyvercolano avatar Aug 08 '22 21:08 anthonyvercolano

I deleted the host name for privacy, but it is there. I have been able to connect to the host using telnet (443 & 8883) and send_message.py.

ikumar222 avatar Aug 08 '22 22:08 ikumar222

I got this error when I used the IoT Hub free tier and I even got the error with Raspberry Pi. However, I tried using the basic tier 1 IoT Hub and I no longer get the error and it works fine.

ikumar222 avatar Aug 11 '22 03:08 ikumar222