Use API by python to get gateway data

Hello ,everyone! I am new in the area of lorawan and chirpstack. I am trying to use API to get gateway data ,but when I use python, I always find an error during the gRPC communication. The following is my code in python.
import requests
import os
import sys
import grpc
import chirpstack_api
from chirpstack_api import api

server = “”

my server host & port

api_token = “”

my api token

channel = grpc.insecure_channel(server)

auth_token = [(“authorization”, “Bearer %s” % api_token)]
def get_data():
client = api.GatewayServiceStub(channel)
req = api.GetGatewayMetricsRequest()
resp = client.GetMetrics(req, metadata=auth_token)
resp.gateway_id = “02819ffffed4f1fd”
resp.start = 1700736381
resp.end = 1701660147
# resp.aggregation = 1
print(resp)

if name == “main”:
get_data()
The following is the error.
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
status = StatusCode.INTERNAL
details = “Invalid string length”
debug_error_string = “UNKNOWN:Error received from peer {grpc_message:“Invalid string length”, grpc_status:13, created_time:“2023-12-12T03:18:37.688138+00:00”}”

If you have advice in my question, I will be very grateful to you ! Thank you very much!

1 Like

Hi,
Try with:
resp.start.seconds = 1700736381
resp.end.seconds = 1701660147

Not tested with the Python lib, but works with direct API call.

Thank you very much! But what is “direct API call”? How does it run?

You can make direct API calls from Postman for instance.

OK, thank you! I will try it again!