Help Urgent with chirpstack and python

I run a local server on my pi 4 and all works well with web-server, i manage to add devices and see the data they are sending.
Now I need 2 things:

1st- need to send payload to device through python script.
It tried the following example:

but i got the following error message code:
Traceback (most recent call last):
  File "/home/pi/hydrosafe/", line 38, in <module>
    resp = client.Enqueue(req, metadata=auth_token)
  File "/home/pi/.local/lib/python3.9/site-packages/grpc/", line 946, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "/home/pi/.local/lib/python3.9/site-packages/grpc/", line 849, in _end_unary_response_blocking
    raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
        status = StatusCode.UNIMPLEMENTED
        details = "unknown method Enqueue for service api.DeviceService"
        debug_error_string = "UNKNOWN:Error received from peer ipv6:%5B::1%5D:8080 {grpc_message:"unknown method Enqueue for service api.DeviceService", grpc_status:12, created_time:"2023-02-24T20:12:00.306978098-03:00"}"
I tried searching for how to solve, but i think is somthing to do with gRPC and i don't understand it.
I don't have time to study it, as i need to deliver a solution assap. If some1 can help me with this.

2nd- I need a python script to receive every message from lowaran devices, to process them and do somthing with the data.
How can i make my python script received the registered lorawan devices data?
If some1 can post an example code i would appreciate it.

Thank you for your time :pray:

as the exception show that “unknown method Enqueue for service api.DeviceService”

the statement on Python examples - ChirpStack open-source LoRaWAN® Network Server documentation shows:
the enquee meth is inDeviceServiceStub
the code is

# Device-queue API client.
client = api.DeviceServiceStub(channel)

# Define the API key meta-data.
auth_token = [("authorization", "Bearer %s" % api_token)]

# Construct request.
req = api.EnqueueDeviceQueueItemRequest()
req.queue_item.confirmed = False = bytes([0x01, 0x02, 0x03])
req.queue_item.dev_eui = dev_eui
req.queue_item.f_port = 10

resp = client.Enqueue(req, metadata=auth_token)

it means the Enquee meth is in api.DeviceServiceStub but not api.DeviceService

the exception says that, but the code is exactly what you posted.
After reading a lot i figured the problem was the api version. i had version V4.
I changed the code to the examples of V3: Python examples - ChirpStack open-source LoRaWAN<sup>®</sup> Network Server
I downgraded to V3.12.4, but now i have other problem:

i downgraded protobuf again from v4.22.0 to v3.20.1 and had the followings warning and problem:

So can some1 tell me which versiosn of chirpstack-api, grpcio, grpcio-tools and protobuff should i use for V3? i tried to upgrade for v4, but i have more problems there. i think this will be faster

ok, finally managed to run it, i had a stupid problem, i have 2 rpi 1 is testing chirpstack v4, the other is testing cirpstack v3. I was generating token for v3 with v4 api (i used the v4 ip to acces the page)(i know stupid).

As for the other problem, with v3, the pip installs for api, for compatibility, should be like this:
$ pip install grpcio-tools==1.42.0
$ pip install chirpstack-api==3.12.4