Skip to content

rest_client.download_ota_package : UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte #62

@ysimonx

Description

@ysimonx

While trying to download a gz file as OTA package thanks to thingsboard-python-rest-client
I have this error

Traceback (most recent call last):
  File "ota.py", line 31, in <module>
    downloads=rest_client.download_ota_package(str(first_package.id.id))
  File "/home/ysimonx/Developpement/thingsboard_ota_py/env/lib/python3.8/site-packages/tb_rest_client/rest_client_ce.py", line 589, in download_ota_package
    return self.ota_package_controller.download_ota_package_using_get(ota_package_id=ota_package_id)
  File "/home/ysimonx/Developpement/thingsboard_ota_py/env/lib/python3.8/site-packages/tb_rest_client/api/api_ce/ota_package_controller_api.py", line 142, in download_ota_package_using_get
    (data) = self.download_ota_package_using_get_with_http_info(ota_package_id, **kwargs)  # noqa: E501
  File "/home/ysimonx/Developpement/thingsboard_ota_py/env/lib/python3.8/site-packages/tb_rest_client/api/api_ce/ota_package_controller_api.py", line 201, in download_ota_package_using_get_with_http_info
    return self.api_client.call_api(
  File "/home/ysimonx/Developpement/thingsboard_ota_py/env/lib/python3.8/site-packages/tb_rest_client/api_client.py", line 409, in call_api
    return self.__call_api(resource_path, method,
  File "/home/ysimonx/Developpement/thingsboard_ota_py/env/lib/python3.8/site-packages/tb_rest_client/api_client.py", line 193, in __call_api
    response_data = self.request(
  File "/home/ysimonx/Developpement/thingsboard_ota_py/env/lib/python3.8/site-packages/tb_rest_client/api_client.py", line 431, in request
    return self.rest_client.GET(url,
  File "/home/ysimonx/Developpement/thingsboard_ota_py/env/lib/python3.8/site-packages/tb_rest_client/rest.py", line 237, in GET
    return self.request("GET", url,
  File "/home/ysimonx/Developpement/thingsboard_ota_py/env/lib/python3.8/site-packages/tb_rest_client/rest.py", line 225, in request
    r.data = r.data.decode('utf8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte


The firmware package is a gz file

and of course, this file can not be considered as a "utf-8" string,

It should not be decoded in line 225 of rest.py

` if _preload_content:
r = RESTResponse(r)

        # In the python 3, the response.data is bytes.
        # we need to decode it to string.
        if six.PY3:
            r.data = r.data.decode('utf8')

`

How to reproduce it :



with RestClientCE(base_url=url) as rest_client:
    try:
       
        rest_client.login(username=username, password=password)

       
        packs = rest_client.get_ota_packages_v1(100,0,None, None, None)

        package = packs.data[0]
        
        downloads=rest_client.download_ota_package(package.id.id)

        print(downloads)
        
    except ApiException as e:
        logging.exception(e)


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions