Python and requesting device details with chirpstack-api failed

I try to read my devices with python and the chirpstack-api library. I am successful in requesting applications, device_grofiles, gateways, list from devices in an application but if I want to request details from a specifig device I get an error.

This is a working code for requesting applications

import grpc
from chirpstack_api import api as chirpstack


with open(chirpstack_pem, "rb") as f:
    credentials = grpc.ssl_channel_credentials(f.read())
channel = grpc.secure_channel(chirpstack_server, credentials)
auth_token = [("authorization", "Bearer %s" % chirpstack_token)]


if __name__ == "__main__":
    client = chirpstack.ApplicationServiceStub(channel)
    req = chirpstack.ListApplicationsRequest()
    req.limit = 10 #mandatory if you want details
    req.offset = 0
    req.tenant_id = tenant_id
    resp = client.List(req, metadata=auth_token)
    print(resp)

Here the code to request a single device

import grpc
from chirpstack_api import api as chirpstack


with open(chirpstack_pem, "rb") as f:
    credentials = grpc.ssl_channel_credentials(f.read())
channel = grpc.secure_channel(chirpstack_server, credentials)
auth_token = [("authorization", "Bearer %s" % chirpstack_token)]


if __name__ == "__main__":
    client = chirpstack.DeviceServiceStub(channel)
    req = chirpstack.GetDeviceRequest()
    req.dev_eui = "343233386B376510"
    resp = client.List(req, metadata=auth_token)
    print(resp)

And this is the error I get:

Traceback (most recent call last):
  File "C:\Users\ckroon\PycharmProjects\chripstack\chirpstack_device.py", line 21, in <module>
    resp = client.List(req, metadata=auth_token)
  File "C:\Users\ckroon\PycharmProjects\chripstack\venv\lib\site-packages\grpc\_channel.py", line 1160, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "C:\Users\ckroon\PycharmProjects\chripstack\venv\lib\site-packages\grpc\_channel.py", line 1003, in _end_unary_response_blocking
    raise _InactiveRpcError(state)  # pytype: disable=not-instantiable
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
	status = StatusCode.INTERNAL
	details = "failed to decode Protobuf message: ListDevicesRequest.limit: invalid wire type: LengthDelimited (expected Varint)"
	debug_error_string = "UNKNOWN:Error received from peer  {grpc_message:"failed to decode Protobuf message: ListDevicesRequest.limit: invalid wire type: LengthDelimited (expected Varint)", grpc_status:13, created_time:"2024-02-09T12:59:42.8224533+00:00"}"
>

Process finished with exit code 1

What could I do to get the correct information? I have the same issue with requesting the device key’s.

Hello, I think there’s a missing step in retrieving a particular device.
An application can contain multiple devices, so we would need a function to retrieve the list of devices within an application using:

req = chirpstack.ListDevicesRequest()
...
resp = client.List(req, metadata=auth_token)

Then, subsenquently, to obtain a particular device:

client = chirpstack.DeviceServiceStub(channel)
req = chirpstack.GetDeviceRequest()
req.dev_eui = "343233386B376510"
resp = client.Get(req, metadata=auth_token)
print(resp)

In your code to retrieve a particular device, you use client.List , I think it should be client.Get .

Thanks for the fast reaction. It was indeed the problem with “client.Get” instead if “client.List”

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.