question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

device client register method fails with CredentialError caused by UnauthorizedError when attempting to connect to a device on iot central using python sdk.

See original GitHub issue

Context

  • OS and version used: Linux 4.19.0-xilinx-v2019.2 on PicoZed
  • Python version: Python 3.7.8
  • pip version: pip 19.2.3
  • list of installed packages: azure-iot-device 2.4.0
  • cloned repo: NA

Description of the issue

We are attempting to check if we can push telemetry data onto a device created in Azure IoT Central by following the tutorial:

https://docs.microsoft.com/en-us/azure/iot-central/core/tutorial-connect-device-python

On running the environmental_sensor.py that we created, we were hit with the following message:

# python3 env_sensor.py
 Device could not connect

We then modified the script to be a sync version of the same using:

https://github.com/Azure/azure-iot-sdk-python/blob/master/azure-iot-device/samples/sync-samples/provision_symmetric_key.py as reference.

Upon running the environmental_sensor.py, we encountered the following error:

azure.iot.device.exceptions.CredentialError: CredentialError('Credentials invalid, could not connect') caused by UnauthorizedError('Connection Refused: not authorised.')

Code sample exhibiting the issue

Here’s the modified script that we used. All it does is register, connect and attempt to send telemetry every 5s - synchronously.

sync_env_sensor.txt

Console log of the issue

~# python3 sync_env_sensor.py
 Traceback (most recent call last):
   File "/usr/lib/python3.7/site-packages/azure/iot/device/provisioning/provisioning_device_client.py", line 25, in handle_result
     return callback.wait_for_completion()
   File "/usr/lib/python3.7/site-packages/azure/iot/device/common/evented_callback.py", line 70, in wait_for_completion
     raise self.exception
 azure.iot.device.common.transport_exceptions.UnauthorizedError: UnauthorizedError('Connection Refused: not authorised.')
    
 The above exception was the direct cause of the following exception:
    
 Traceback (most recent call last):
   File "sync_env_sensor.py", line 25, in <module>
     registration_result = provisioning_device_client.register()
   File "/usr/lib/python3.7/site-packages/azure/iot/device/provisioning/provisioning_device_client.py", line 73, in register
     self._enable_responses()
   File "/usr/lib/python3.7/site-packages/azure/iot/device/provisioning/provisioning_device_client.py", line 96, in _enable_responses
     handle_result(subscription_complete)
   File "/usr/lib/python3.7/site-packages/azure/iot/device/provisioning/provisioning_device_client.py", line 35, in handle_result
     raise exceptions.CredentialError(message="Credentials invalid, could not connect", cause=e)
 azure.iot.device.exceptions.CredentialError: CredentialError('Credentials invalid, could not connect') caused by UnauthorizedError('Connection Refused: not authorised.')

This issue has also been raised @ https://docs.microsoft.com/en-us/answers/questions/154410/device-client-register-method-fails-with-credentia.html

Any help will be greatly appreciated.

AB#8828384

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
elhortoncommented, Nov 19, 2020

Hi @avwater , unfortunately we are unable to repro this issue with the tutorial. We will work with Satish (from your Microsoft Q&A post) to communicate with you and find a root cause. For now, let’s use that channel. We’ll leave this open in the meantime and return to it when we have a solution.

0reactions
elhortoncommented, Jan 19, 2021

@kodonnell , thanks for following up on this! Could you please file the issue with WSL? that is not a known bug to my knowledge, and we will coordinate with the IoT Central team. The initial resolution was having the appropriate roles set (need to be an application Administrator), but it sounds like your issue may be different.

Here’s a verbatim explanation for this issue:

_To access and use the Administration section, you must be in the Administrator role for an Azure IoT Central application. If you create an Azure IoT Central application, you’re automatically added to the Administrator role for that application. For more information, see Manage users and roles in Azure IoT Central application.

You can either create your own IoT Central application for testing and to run the tutorial, in which case you’ll be in Administrator role automatically. Or, you can ask someone who is in the Administrator role for your application to retrieve the group SAS key for you._

Read more comments on GitHub >

github_iconTop Results From Across the Web

device client register method fails with CredentialError caused ...
device client register method fails with CredentialError caused by UnauthorizedError when attempting to connect to a device on iot central using python sdk....
Read more >
Microsoft Azure IoT Python SDK Can Successfully Provision ...
Now, I am trying to connect ( not provision ) with the credentials I used to successfully provision and connect above using the...
Read more >
Connect Edge Devices to Microsoft Azure* IoT​ - Intel
Deployment manifest is used to configure and deploy modules to IoT Edge device from Azure IoT Hub/IoT Central. 1. Go to ~/Desktop/ ...
Read more >
Azure IoT Central: Home
Connect your phone and go from zero to live data in five minutes with our app. Or get started with Azure Certified Devices...
Read more >
Azure IoT DeviceClient SDK Python demonstration, the basics
The Azure IoT Hub is a so-called cloud gateway for IoT Devices. It serves four main purposes: Device identities can be registered so...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found