openBalena Internal Server Error on device registration with Python SDK

Hello!

I am hoping to use the Balena Python SDK to pre-register my devices so that I can set critical environment variables at the same time the SD card is flashed.

However, when my python script executes balena.models.device.register(<my_application_name>, <32_character_UUID>)

I receive an internal server error.

Here is my balena.cfg file (I am running openBalena 2, not 3 yet):

[Settings]
pine_endpoint = https://api.<my_domain>/v5/
api_endpoint = https://api.<my_domain>/
builder_url = https://builder.balena-cloud.com/
api_version = v5
device_actions_endpoint_version = v1
data_directory = C:\Users\Caleb\.balena
image_cache_time = 604800000
token_refresh_interval = 3600000
timeout = 30000
cache_directory = C:\Users\Caleb\.balena\cache
token = <my_token>

Any ideas?

Hi Caleb, check out the logs for the API service and see if you can find the exception. That can help us diagnose.

The Python API? How?

Hi Caleb,

We actually meant the logs printed by the open-balena-api container that’s running on your server.
Let me point you to the template part of the respective docker-compose service:

Once you get a terminal session to the open-balena server, you should be able to do a docker ps to grab the API container name and just use journalctl -f -n 100 -u <CONTAINER_NAME> to start seeing the emitted logs.

Kind regards,
Thodoris

I have attached my logs from the docker ps (docker-ps.log) and journalctl -f -n 100 -u openbalena_api_1 (journalctl-api.log). Since the journalctl didn’t show any logs, I also tried without the -u flag and have attached that output (journalctl.log)

Any ideas as to why the journalctl command you gave didn’t show anything? Do I need to log in as a particular user? I did make sure to test out the code which produces the error while the journalctl was running.

docker-ps.log (2.1 KB) journalctl-api.log (49 Bytes) journalctl.log (11.2 KB)

Hey there it seems there were no logs from that service?

can you try to get the logs directly while trying to run the test code again using docker logs --follow <container ID>?

in your case that would docker logs --follow 291fa7767aac

Thanks

I got it working! The example in the documentation here indicates that you should pass in the application name, however after poking around the API code I tried passing in the application ID instead, and everything worked!

Are there any plans to consolidate the use of the app id vs the application name throughout the API? I get confused switching between the two, in my mind it would make sense to just pick one way to reference an app via the SDK.

1 Like

Hi there Caleb,

I completely agree that there should be consistency, and in fact we already have an issue open on the Python SDK to bring it inline with the node.js SDK and support id, device UUID and the application name:

I’m glad you’ve got up and running now.
Phil

Glad to hear it! Thanks!