2017-09-09 2 views
0

ここでは、サーバーからメタデータを送信する方法を示します。ここでpython gRPCクライアントから後続のメタデータにアクセスする方法

def DoSomething(self, request, context): 
    response = detection2g_pb2.SomeResponse() 
    response.message = 'done' 
    _SERVER_TRAILING_METADATA = (
           ('method_status', '1010'), 
            ('error', 'No Error') 
           ) 
    context.set_trailing_metadata(_SERVER_TRAILING_METADATA) 

    return response 

は、私が試したものです。この場合は

res = _stub.DoSomething(req) 
    print (res.trailing_metadata()) 

私はエラーオブジェクトが属性「trailing_metadata」を持っていない属性を取得します。クライアント側のメタデータにアクセスする方法を知りたい

+0

あなたの質問には関係ないが、患者がテーブルに載っている間:私は、あなたが現在のコードで持っている別々の構築文と突然変異文ではなく、 'response = detection2g_pb2.SomeResponse(message = 'done')' 。次に、 'return detection2g_pb2.SomeResponse(message = 'done')'と書いてローカルフィールドを削除します。 –

+1

意味があります。ありがとう –

答えて

1

私はwe don't yet have an example illustrating metadataことを謝罪ができますが、here how getting the trailing metadata on the invocation side requires using with_call見ることができます(またはfutureを、それはあなたが変更したくないような方法で制御の流れを変更することがあり、私はwith_callがあなたの最初の選択肢でなければならないことだと思います)。あなたの呼び出し側コードは、

response, call = _stub.DoSomething.with_call(request) 
print(call.trailing_metadata()) 

のように見えるはずです。

関連する問題