What is the solution to the error when sending websocket message to Yandex API Gateway using Yandex Cloud Python SDK?
"Failed to send message: <_InactiveRpcError of RPC that terminated with: status = StatusCode.UNIMPLEMENTED details = "" debug_error_string = "UNKNOWN:Error received from peer ipv4:xx.xxx.xxx.xx:443 {created_time:"2023-02-07T02:45:12.348129344+00:00", grpc_status:12, grpc_message:""}"
Here is the code I use, without any success. I still can connect and send messages via Postman or cmd.
import json
import os
import yandexcloud
import grpc
from yandex.cloud.serverless.apigateway.websocket.v1.connection_service_pb2_grpc import ConnectionServiceStub
from yandex.cloud.serverless.apigateway.websocket.v1.connection_service_pb2 import SendToConnectionRequest
script_dir = os.path.dirname(__file__)
rel_path = "authorized_key.json"
abs_file_path = os.path.join(script_dir, rel_path)
with open(abs_file_path) as json_file:
sa_key = json.load(json_file)
sdk = yandexcloud.SDK(service_account_key=sa_key)
ws_client = sdk.client(ConnectionServiceStub)
ws_request = SendToConnectionRequest(
connection_id='some_existing_connection_id',
data=b'some_binary_data',
type=SendToConnectionRequest.BINARY
)
try:
response = ws_client.Send(ws_request)
print(f"Message sent successfully: {response}")
except grpc.RpcError as error:
print(f"Failed to send message: {error}")