无法连接到python中的所有地址grpc

发布于 2025-01-14 04:56:24 字数 1455 浏览 5 评论 0原文

我正在尝试使用 grpc 并使用下面的脚本将数据发布到 arangodb,但在运行客户端时出现上述错误,我的服务器运行良好,无法找出错误在哪里

from inspect import trace
import re
from urllib import response
import grpc
import os
import first_pb2_grpc as pb2_grpc
import first_pb2 as pb2
import json
import grpc
from typing import Dict, List
from google.protobuf import json_format 
from first_pb2_grpc import*
import traceback
test_data_file_name = "data.json"
curr_dir = os.path.dirname(os.path.realpath(__file__))

test_data_file = os.path.join(curr_dir,test_data_file_name)
def read_json_file(file):
    with open(file, encoding="utf8") as f:
        data = json.load(f)
    return data

test_data = read_json_file(test_data_file)

channel = grpc.insecure_channel('localhost:31024')

stub = pb2_grpc.UnaryStub(channel)

def test(request):
    try:
        response = stub.GetServerResponse(request)
        print(response , 'AAAAA')
        return response
    except Exception as e:
        return str(e)

def test_add_name(message):
    try:
        request = pb2.Message(
            message=message
        )
        test_response = test(request)
        
        return test_response
    except Exception as e:
        traceback.print_exc()
        return str(e)



if __name__ == "__main__":
    message = test_data["message"]
    #attribute_val = json_format.Parse(json.dumps(name) , message='hi') 
    api_response = test_add_name(message)
    print(api_response)

请告诉我如何解决此问题

I am trying to post data to arangodb using grpc and using script below but while running the client getting above error , My server is running in a good way,unable to figure out where is the error

from inspect import trace
import re
from urllib import response
import grpc
import os
import first_pb2_grpc as pb2_grpc
import first_pb2 as pb2
import json
import grpc
from typing import Dict, List
from google.protobuf import json_format 
from first_pb2_grpc import*
import traceback
test_data_file_name = "data.json"
curr_dir = os.path.dirname(os.path.realpath(__file__))

test_data_file = os.path.join(curr_dir,test_data_file_name)
def read_json_file(file):
    with open(file, encoding="utf8") as f:
        data = json.load(f)
    return data

test_data = read_json_file(test_data_file)

channel = grpc.insecure_channel('localhost:31024')

stub = pb2_grpc.UnaryStub(channel)

def test(request):
    try:
        response = stub.GetServerResponse(request)
        print(response , 'AAAAA')
        return response
    except Exception as e:
        return str(e)

def test_add_name(message):
    try:
        request = pb2.Message(
            message=message
        )
        test_response = test(request)
        
        return test_response
    except Exception as e:
        traceback.print_exc()
        return str(e)



if __name__ == "__main__":
    message = test_data["message"]
    #attribute_val = json_format.Parse(json.dumps(name) , message='hi') 
    api_response = test_add_name(message)
    print(api_response)

Please tell me how can i resolve this

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文