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
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!
import grpc
from chirpstack_api import api
# Need to import this to create timestamp object
from google.protobuf.timestamp_pb2 import Timestamp
# API interface.
server = "localhost:8080"
# Use this API token: Network API Key
api_token = "token"
# Connect without using TLS.
channel = grpc.insecure_channel(server)
# API client configuration.
gtw_client = api.GatewayServiceStub(channel)
# Define the API key meta-data.
auth_token = [("authorization", "Bearer %s" % api_token)]
try:
# Create timestamps
start = Timestamp()
start.FromSeconds(1700736381)
end = Timestamp()
end.FromSeconds(1701660147)
req = api.GetGatewayMetricsRequest(gateway_id="id", start=start, end=end)
resp = gtw_client.GetMetrics(req, metadata=auth_token)
except Exception as e:
print("Exception occurred: " + str(e))
print(resp)