Hi everyone, I am using the Balena Python-SDK to make API calls and retrieve data from Balena. I usually face the issues of “Unauthorized” requests quite often, and I don’t really know what the root cause is. I read somewhere that the Balena team throttles the login requests per day, so if you pass a certain limit then you cannot log in anymore. Could you please confirm these issues and provide alternative solutions to it?
The reason why I use the Python-SDK over Belana CLI is that I need the output to send it elsewhere, but on the command line, I’m really limited to what I can do with the data I retrieve.
Here is the sample code that I run which faces the problem (I don’t know after how many attempts):
Class BalenaHandler():
def __init__(self, uuid):
"""
:param: uuid (str) : the machine id
"""
self.balena = Balena()
self.balena.auth.login_with_token(config.BALENA_AUTH_TOKEN)
self.UUID = uuid
then executing a simple function like:
def get_device_name(self):
"""
Get the device name
:param: none
:return: device name (str)
"""
return self.balena.models.device.get_name(self.UUID)
Creates the following error:
Traceback (most recent call last):
File "BalenaCloudHandler.py", line 173, in <module>
bh = BalenaHandler(uuid)
File "BalenaCloudHandler.py", line 25, in __init__
print(self.balena.models.api_key.get_all())
File "/usr/local/lib/python3.6/dist-packages/balena/models/api_key.py", line 58, in get_all
endpoint=self.settings.get('pine_endpoint')
File "/usr/local/lib/python3.6/dist-packages/balena/base_request.py", line 197, in request
raise exceptions.RequestError(response._content)
balena.exceptions.RequestError: b'Unauthorized'