は私のプロトファイルです:grpc不正なワイヤータイプ:2(予想0))ここで
syntax = "proto3";
package grpcClient;
service GrpcClient {
rpc GetPeople(PeopleRequest) returns (PeopleResponse) {}
}
message PeopleRequest {
repeated string names = 1; // ex: ['jack', 'marie']
repeated int32 ages = 2; // ex: [18, 24]
}
message PeopleResponse {
repeated Person people = 1;
}
message Person {
string name = 1;
int32 age = 2;
}
そして、ここでのpythonスタブ構造である:
from . import grpcClient_pb2
class GrpcClient:
def __init__(self):
server_url = "http://my_url:5001"
secure_channel = make_secure_channel(server_url)
self.__stub = grpcClient_pb2.GrpcClientStub(secure_channel)
def get_people(self, **kwargs):
people_request = grpcClient_pb2.PeopleRequest(**kwargs)
# your test example
try:
serialized_people_request = grpcClient_pb2.PeopleRequest.SerializeToString(people_request)
except Exception as e:
print(e)
else:
print('Serialized to binary of type {} and length {}'.format(type(serialized_people_request), len(serialized_people_request)))
return self.__stub.GetPeople(people_request) # this throw an error
、ここでは私のgrpc呼び出しです:
grpcClient = GrpcClient()
grpcClient.get_people({ 'names': ['daniel', 'jack'] }) # this is OK
grpcClient.get_people({ 'names': ['daniel', 'jack'], 'ages': [18, 22] }) # this throws
私が使用のPython 3.6と私のピップpacka GESのバージョンは次のとおりです。
grpcio 1.0.4
grpcio-tools 1.0.4
pip 9.0.1
protobuf 3.1.0.post1
私は、このコマンドを使用してgrpcClient_pb2.py
とgrpcClient_pb2_grpc.py
を生成します。
python -m grpc.tools.protoc -I./ --python_out=./ --grpc_python_out=./ ./grpcClient.proto
注:
_descriptor.FieldDescriptor(
name='names', full_name='PeopleRequest.names', index=0,
number=1, type=9, cpp_type=9, label=3,
has_default_value=False, default_value=[],
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='ages', full_name='PeopleRequest.ages', index=1,
number=2, type=5, cpp_type=1, label=3,
has_default_value=False, default_value=[],
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
多くのおかげで:ここには、自動生成されたPythonのコードですあなたは助けてくれます!
ご迷惑をおかけして申し訳ありません。このチケットの詳細については、https://github.com/grpc/grpc/issues/9439を参照してください。あなたの例は私のコードに非常に似ています。多分それは別のpython/grpc/protobufバージョンです...?私は今キーボードから離れています、私はすぐにさらに調査を行います – Sulliwane
あなたが使用しているバージョン(python/protobuf/grpcio)を教えてもらえますか?test_pb2とtest_pb2_grpcはどうやって生成しますか?ありがとう – Sulliwane
は、python 3.5で同じエラーを投げてみました。私はあなたの輸入に興味があります: '' 'test_pb2、import test_pb2_grpc'''、私には' 'test_pb2_grpc'''に問題の原因となる重複インポートがたくさんあるので、それをスキップして使用しますStubの定義は '' '' 'test_pb2'''''でも利用できます。 – Sulliwane