Unable to download BalenaOS Images using PythonSDK


Im using the Balena Python SDK to download balenaOS images and im getting this error,

Traceback (most recent call last):
File “test_download.py”, line 6, in
r = balena.models.device_os.download(**data)
File “/home/eis/.local/lib/python2.7/site-packages/balena/models/device_os.py”, line 102, in download
endpoint=self.settings.get(‘api_endpoint’), stream=True, login=True
File “/home/eis/.local/lib/python2.7/site-packages/balena/base_request.py”, line 182, in request
stream=stream, auth=auth, api_key=api_key, raw_query=raw_query)
File “/home/eis/.local/lib/python2.7/site-packages/balena/base_request.py”, line 145, in __request
return request_method(url, headers=headers, data=data, stream=stream)
File “/home/eis/.local/lib/python2.7/site-packages/balena/base_request.py”, line 54, in __post
url, data=json.dumps(self.util.decode_utf8(data)), headers=headers, stream=stream, timeout=self.timeout)
File “/home/eis/.local/lib/python2.7/site-packages/requests/api.py”, line 116, in post
return request(‘post’, url, data=data, json=json, **kwargs)
File “/home/eis/.local/lib/python2.7/site-packages/requests/api.py”, line 60, in request
return session.request(method=method, url=url, **kwargs)
File “/home/eis/.local/lib/python2.7/site-packages/requests/sessions.py”, line 533, in request
resp = self.send(prep, **send_kwargs)
File “/home/eis/.local/lib/python2.7/site-packages/requests/sessions.py”, line 646, in send
r = adapter.send(request, **kwargs)
File “/home/eis/.local/lib/python2.7/site-packages/requests/adapters.py”, line 529, in send
raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host=‘api.balena-cloud.com’, port=443): Read timed out. (read timeout=30.0)

python code:

from balena import Balena                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
balena = Balena()                                                                                                                                                                                                                                                         
data = {'appId': '<app_id>', 'version': 'balenaOS 2.41.1+rev1', 'network': 'ethernet'}
r = balena.models.device_os.download(**data)
with open('balena.img', 'wb') as save_file:

Hi rossm,
I was able to replicate the error with the SDK. I asked the maintainer to take a look and post back.
Just in case it’s relevant, what version of the sdk are you running?

Hi @tmigone,

Thanks for the quick reply! I am running balena sdk version 9.0.0. Looking forward to hearing back.


Hi @rossm,
Could you clarify the device type of the application for which you are trying to download that image?

Since this is the openBalena section of our forums, I would like to also clarify that by checking the pasted error logs, I realize that you are probably using the balena-cloud API.

Kind regards,

Hello @rossm, just wanted to followup quickly to see if you had any luck downloading images via the SDK, or, needed any further assistance. Let us know!

Hello team! Also error with openBalena and NodeSDK:

balena.models.os.download(deviceType, version)

web_1 |
web_1 | ERROR { 09:29:49
web_1 | statusCode: 404,
web_1 | duration: 105,
web_1 | method: ‘GET’,
web_1 | url: ‘/download?deviceType=raspberrypi3&version=2.29.0+rev1.prod’,

Do not work from 12.12.0 , maybe earlier. Please check.

balena-cli also same

OpenBalena does not support image downloads – you have to get the images from balena.io/os.

1 Like

Thank you for answer. But it works with “balena-sdk”: “12.10.0”

Are you sure? The openBalena API has no /download endpoint and from the logs above you can see the SDK clearly tries to reach that endpoint, and as a matter of fact, gets a 404 response.

In source of version 12.10.0 i see:

deviceImageUrl = (deviceType, version) ->

and it works with openBalena

Back to original discussion, @rossm the exception shows that the request timed out, it should be transient but I recommend you check your local network for any issues.

That /image endpoint is reaching out to the Image Maker, not the API, which is a component that is not included with openBalena. Image downloads with openBalena were never supported.

Ok, thank you. I see now:

12.12.0 - 2019-09-28

  • Deprecate the imageMakerUrl constructor option [Thodoris Greasidis]
  • Drop the image maker helper [Thodoris Greasidis]
  • Use the cloud API endpoint for downloading unconfigured images [Thodoris Greasidis]

Sorry for oftopic, i thought this topic is situated in openBalena thread =(

No problem, you’re wlecome :slight_smile: