2017-09-09 58 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

有意義。謝謝 –

回答