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 issueContext
- 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.
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:
- Created 3 years ago
- Comments:12 (6 by maintainers)
Top GitHub Comments
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.
@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._