thingsboard-python-rest-client icon indicating copy to clipboard operation
thingsboard-python-rest-client copied to clipboard

example_application.py fails with 'Device profile type should be specified!"'

Open ardrabczyk opened this issue 1 year ago • 0 comments

[ja:/home/ja/thingsboard-python-rest-client/examples] master ± PYTHONPATH=.. python3 example_application.py
2024-01-17 12:51:33 - INFO - example_application - 46 - Asset was created:
{'additional_info': None,
 'asset_profile_id': {'entity_type': 'ASSET_PROFILE',
                      'id': '63eb9290-b52e-11ee-b742-57063ee55db6'},
 'created_time': 1705492293837,
 'customer_id': {'entity_type': 'CUSTOMER',
                 'id': '13814000-1dd2-11b2-8080-808080808080'},
 'id': {'entity_type': 'ASSET', 'id': 'c2eb07d0-b52e-11ee-a16c-23dd3519e206'},
 'label': 'Building 1',
 'name': 'Building 1',
 'tenant_id': {'entity_type': 'TENANT',
               'id': '63e1ce90-b52e-11ee-b742-57063ee55db6'},
 'type': 'default'}

2024-01-17 12:51:33 - ERROR - example_application - 67 - (400)
Reason:
HTTP response headers: HTTPHeaderDict({'Vary': 'Origin, Access-Control-Request-Method, Access-Control-Request-Headers', 'X-Content-Type-Options': 'nosniff', 'X-XSS-Protection': '1; mode=block', 'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'Content-Type': 'application/json;charset=ISO-8859-1', 'Content-Length': '108', 'Date': 'Wed, 17 Jan 2024 11:51:33 GMT', 'Connection': 'close'})
HTTP response body: b'{"status":400,"message":"Device profile type should be specified!","errorCode":31,"timestamp":1705492293848}'
Traceback (most recent call last):
  File "example_application.py", line 54, in main
    device_profile = rest_client.save_device_profile(device_profile)
  File "/home/ja/thingsboard-python-rest-client/tb_rest_client/rest_client_ce.py", line 991, in save_device_profile
    return self.device_profile_controller.save_device_profile_using_post(body=body)
  File "/home/ja/thingsboard-python-rest-client/tb_rest_client/api/api_ce/device_profile_controller_api.py", line 951, in save_device_profile_using_post
    (data) = self.save_device_profile_using_post_with_http_info(**kwargs)  # noqa: E501
  File "/home/ja/thingsboard-python-rest-client/tb_rest_client/api/api_ce/device_profile_controller_api.py", line 1011, in save_device_profile_using_post_with_http_info
    return self.api_client.call_api(
  File "/home/ja/thingsboard-python-rest-client/tb_rest_client/api_client.py", line 406, in call_api
    return self.__call_api(resource_path, method,
  File "/home/ja/thingsboard-python-rest-client/tb_rest_client/api_client.py", line 192, in __call_api
    response_data = self.request(
  File "/home/ja/thingsboard-python-rest-client/tb_rest_client/api_client.py", line 448, in request
    return self.rest_client.POST(url,
  File "/home/ja/thingsboard-python-rest-client/tb_rest_client/rest.py", line 288, in POST
    return self.request("POST", url,
  File "/home/ja/thingsboard-python-rest-client/tb_rest_client/rest.py", line 247, in request
    raise ApiException(http_resp=r)
tb_rest_client.rest.ApiException: (400)
Reason:
HTTP response headers: HTTPHeaderDict({'Vary': 'Origin, Access-Control-Request-Method, Access-Control-Request-Headers', 'X-Content-Type-Options': 'nosniff', 'X-XSS-Protection': '1; mode=block', 'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'Content-Type': 'application/json;charset=ISO-8859-1', 'Content-Length': '108', 'Date': 'Wed, 17 Jan 2024 11:51:33 GMT', 'Connection': 'close'})
HTTP response body: b'{"status":400,"message":"Device profile type should be specified!","errorCode":31,"timestamp":1705492293848}'

This would fix it:

device_profile = DeviceProfile(name="Thermometer", type="DEFAULT", transport_type="DEFAULT",
                               profile_data=DeviceProfileData(configuration={"type": "DEFAULT"},
                                                              transport_configuration={"type": "DEFAULT"}))

but I wonder if it's a bug in the client or in Thingsboard server?

ardrabczyk avatar Jan 17 '24 12:01 ardrabczyk