欢迎光临
我们一直在努力

Python grpc.secure_channel方法代码示例

本文整理汇总了Python中grpc.secure_channel方法的典型用法代码示例。如果您正苦于以下问题:Python grpc.secure_channel方法的具体用法?Python grpc.secure_channel怎么用?Python grpc.secure_channel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在grpc的用法示例。

在下文中一共展示了grpc.secure_channel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import secure_channel [as 别名]
def __init__(self, connect_info):

        self._vmid = connect_info[0]
        self._host = connect_info[1]
        self._port = connect_info[2]
        self._stub = None
        self._channel = None

        client_cert = Config().batch.client_cert
        credential = grpc.ssl_channel_credentials(
            root_certificates=client_cert.ca_cert,
            private_key=client_cert.key,
            certificate_chain=client_cert.cert
        )
        self._channel = grpc.secure_channel(
            self._host + ":" + self._port, credential)

        self._stub = agent_pb2_grpc.pcoccNodeStub(self._channel) 
开发者ID:cea-hpc,项目名称:pcocc,代码行数:20

示例2: run

# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import secure_channel [as 别名]
def run(host, port, api_key, auth_token, timeout, use_tls):
    """Makes a basic ListShelves call against a gRPC Bookstore server."""

    if use_tls:
        with open('../roots.pem', 'rb') as f:
            creds = grpc.ssl_channel_credentials(f.read())
        channel = grpc.secure_channel('{}:{}'.format(host, port), creds)
    else:
        channel = grpc.insecure_channel('{}:{}'.format(host, port))

    stub = bookstore_pb2_grpc.BookstoreStub(channel)
    metadata = []
    if api_key:
        metadata.append(('x-api-key', api_key))
    if auth_token:
        metadata.append(('authorization', 'Bearer ' + auth_token))
    shelves = stub.ListShelves(empty_pb2.Empty(), timeout, metadata=metadata)
    print('ListShelves: {}'.format(shelves)) 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:20

示例3: lndDecodeInvoice

# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import secure_channel [as 别名]
def lndDecodeInvoice(lnInvoiceString):
    try:
        # call LND GRPC API
        macaroon = codecs.encode(open(LND_ADMIN_MACAROON_PATH, 'rb').read(), 'hex')
        os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
        cert = open(LND_TLS_PATH, 'rb').read()
        ssl_creds = grpc.ssl_channel_credentials(cert)
        channel = grpc.secure_channel("{0}:10009".format(LND_IP), ssl_creds)
        stub = rpcstub.LightningStub(channel)
        request = lnrpc.PayReqString(
            pay_req=lnInvoiceString,
        )
        response = stub.DecodePayReq(request, metadata=[('macaroon', macaroon)])

        # validate results
        if response.num_msat <= 0:
            print("error='ZERO INVOICES NOT ALLOWED'")
            return  

    except Exception as e:
        print("error='FAILED LND INVOICE DECODING'")
        return

    return response 
开发者ID:rootzoll,项目名称:raspiblitz,代码行数:26

示例4: lndPayInvoice

# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import secure_channel [as 别名]
def lndPayInvoice(lnInvoiceString):
    try:
        # call LND GRPC API
        macaroon = codecs.encode(open(LND_ADMIN_MACAROON_PATH, 'rb').read(), 'hex')
        os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
        cert = open(LND_TLS_PATH, 'rb').read()
        ssl_creds = grpc.ssl_channel_credentials(cert)
        channel = grpc.secure_channel("{0}:10009".format(LND_IP), ssl_creds)
        stub = rpcstub.LightningStub(channel)
        request = lnrpc.SendRequest(
            payment_request=lnInvoiceString,
        )
        response = stub.SendPaymentSync(request, metadata=[('macaroon', macaroon)])

        # validate results
        if len(response.payment_error) > 0:
            print("error='PAYMENT FAILED'")
            print("error_detail='{}'".format(response.payment_error))
            return  

    except Exception as e:
       print("error='FAILED LND INVOICE PAYMENT'")
       return

    return response 
开发者ID:rootzoll,项目名称:raspiblitz,代码行数:27

示例5: main

# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import secure_channel [as 别名]
def main():
    os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
    cert = open('/mnt/hdd/lnd/tls.cert', 'rb').read()
    ssl_creds = grpc.ssl_channel_credentials(cert)
    channel = grpc.secure_channel('localhost:10009', ssl_creds)
    stub = lnrpc.WalletUnlockerStub(channel)

    wallet_password, seed_words, seed_password, file_path_scb = parse_args()

    if mode == "new":
        print("# *** CREATING NEW LND WALLET ***")
        new(stub, wallet_password)

    elif mode == "seed":
        print("# *** RECOVERING LND WALLET FROM SEED ***")
        seed(stub, wallet_password, seed_words, seed_password)

    elif mode == "scb":
        print("# *** RECOVERING LND WALLET FROM SEED + SCB ***")
        scb(stub, wallet_password, seed_words, seed_password, file_path_scb) 
开发者ID:rootzoll,项目名称:raspiblitz,代码行数:22

示例6: getText2VoiceStream

# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import secure_channel [as 别名]
def getText2VoiceStream(inText,inFileName):

    channel = grpc.secure_channel('{}:{}'.format(HOST, PORT), getCredentials())
    stub = gigagenieRPC_pb2_grpc.GigagenieStub(channel)

    message = gigagenieRPC_pb2.reqText()
    message.lang=0
    message.mode=0
    message.text=inText
    writeFile=open(inFileName,'wb')
    for response in stub.getText2VoiceStream(message):
        if response.HasField("resOptions"):
            print ("\n\nResVoiceResult: %d" %(response.resOptions.resultCd))
        if response.HasField("audioContent"):
            print ("Audio Stream\n\n")
            writeFile.write(response.audioContent)
    writeFile.close()
    return response.resOptions.resultCd 
开发者ID:gigagenie,项目名称:ai-makers-kit,代码行数:20

示例7: getVoice2Text

# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import secure_channel [as 别名]
def getVoice2Text():	
    print ("\n\n음성인식을 시작합니다.\n\n종료하시려면 Ctrl+\ 키를 누루세요.\n\n\n")
    
    channel = grpc.secure_channel('{}:{}'.format(HOST, PORT), getCredentials())
    stub = gigagenieRPC_pb2_grpc.GigagenieStub(channel)
    request = generate_request()
    resultText = ''
    for response in stub.getVoice2Text(request):
        if response.resultCd == 200: # partial
            print('resultCd=%d | recognizedText= %s' 
                  % (response.resultCd, response.recognizedText))
            resultText = response.recognizedText
        elif response.resultCd == 201: # final
            print('resultCd=%d | recognizedText= %s' 
                  % (response.resultCd, response.recognizedText))
            resultText = response.recognizedText
            break
        else:
            print('resultCd=%d | recognizedText= %s' 
                  % (response.resultCd, response.recognizedText))
            break

    print ("\n\n인식결과: %s \n\n\n" % (resultText).encode('utf-8'))
    return resultText 
开发者ID:gigagenie,项目名称:ai-makers-kit,代码行数:26

示例8: getText2VoiceUrl

# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import secure_channel [as 别名]
def getText2VoiceUrl(inText):

    channel = grpc.secure_channel('{}:{}'.format(HOST, PORT), getCredentials())
    stub = gigagenieRPC_pb2_grpc.GigagenieStub(channel)

    message = gigagenieRPC_pb2.reqText()
    message.lang=0
    message.mode=0
    message.text=inText
    response = stub.getText2VoiceUrl(message)

    print ("\n\nresultCd: %d" % (response.resultCd))
    if response.resultCd == 200:
        print ("TTS 생성에 성공하였습니다.\n\n\n아래 URL을 웹브라우져에 넣어보세요.")
        print ("Stream Url: %s\n\n" % (response.url))
    else:
        print ("TTS 생성에 실패하였습니다.")
        print ("Fail: %d" % (response.resultCd)) 
开发者ID:gigagenie,项目名称:ai-makers-kit,代码行数:20

示例9: getText2VoiceStream

# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import secure_channel [as 别名]
def getText2VoiceStream(inText,inFileName):

    channel = grpc.secure_channel('{}:{}'.format(HOST, PORT), getCredentials())
    stub = gigagenieRPC_pb2_grpc.GigagenieStub(channel)

    message = gigagenieRPC_pb2.reqText()
    message.lang=0
    message.mode=0
    message.text=inText
    writeFile=open(inFileName,'wb')
    for response in stub.getText2VoiceStream(message):
        if response.HasField("resOptions"):
            print ("ResVoiceResult: %d" %(response.resOptions.resultCd))
        if response.HasField("audioContent"):
            print ("Audio Stream")
            writeFile.write(response.audioContent)
    writeFile.close() 
开发者ID:gigagenie,项目名称:ai-makers-kit,代码行数:19

示例10: getVoice2Text

# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import secure_channel [as 别名]
def getVoice2Text():    

    print ("Ctrl+\ to quit ...")
    
    channel = grpc.secure_channel('{}:{}'.format(HOST, PORT), getCredentials())
    stub = gigagenieRPC_pb2_grpc.GigagenieStub(channel)
    request = generate_request()
    resultText = ''
    for response in stub.getVoice2Text(request):
        if response.resultCd == 200: # partial
            print('resultCd=%d | recognizedText= %s' 
                  % (response.resultCd, response.recognizedText))
            resultText = response.recognizedText
        elif response.resultCd == 201: # final
            print('resultCd=%d | recognizedText= %s' 
                  % (response.resultCd, response.recognizedText))
            resultText = response.recognizedText
            break
        else:
            print('resultCd=%d | recognizedText= %s' 
                  % (response.resultCd, response.recognizedText))
            break

    print ("TEXT: %s" % (resultText))
    return resultText 
开发者ID:gigagenie,项目名称:ai-makers-kit,代码行数:27

示例11: getVoice2Text

# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import secure_channel [as 别名]
def getVoice2Text():	

    print ("Ctrl+\ to quit ...")
    
    channel = grpc.secure_channel('{}:{}'.format(HOST, PORT), getCredentials())
    stub = gigagenieRPC_pb2_grpc.GigagenieStub(channel)
    request = generate_request()
    resultText = ''
    for response in stub.getVoice2Text(request):
        if response.resultCd == 200: # partial
            print('resultCd=%d | recognizedText= %s' 
                  % (response.resultCd, response.recognizedText))
            resultText = response.recognizedText
        elif response.resultCd == 201: # final
            print('resultCd=%d | recognizedText= %s' 
                  % (response.resultCd, response.recognizedText))
            resultText = response.recognizedText
            break
        else:
            print('resultCd=%d | recognizedText= %s' 
                  % (response.resultCd, response.recognizedText))
            break

    print ("TEXT: %s" % (resultText))
    return resultText 
开发者ID:gigagenie,项目名称:ai-makers-kit,代码行数:27

示例12: getText2VoiceStream

# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import secure_channel [as 别名]
def getText2VoiceStream(inText,inFileName):

    channel = grpc.secure_channel('{}:{}'.format(HOST, PORT), UA.getCredentials())
    stub = gigagenieRPC_pb2_grpc.GigagenieStub(channel)

    message = gigagenieRPC_pb2.reqText()
    message.lang=0
    message.mode=0
    message.text=inText
    writeFile=open(inFileName,'wb')
    for response in stub.getText2VoiceStream(message):
        if response.HasField("resOptions"):
            print ("\n\nResVoiceResult: %d" %(response.resOptions.resultCd))
        if response.HasField("audioContent"):
            print ("Audio Stream\n\n")
            writeFile.write(response.audioContent)
    writeFile.close()
    return response.resOptions.resultCd 
开发者ID:gigagenie,项目名称:ai-makers-kit,代码行数:20

示例13: getVoice2Text

# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import secure_channel [as 别名]
def getVoice2Text():	
    print ("\n\n음성인식을 시작합니다.\n\n종료하시려면 Ctrl+\ 키를 누루세요.\n\n\n")
    channel = grpc.secure_channel('{}:{}'.format(HOST, PORT), UA.getCredentials())
    stub = gigagenieRPC_pb2_grpc.GigagenieStub(channel)
    request = generate_request()
    resultText = ''
    for response in stub.getVoice2Text(request):
        if response.resultCd == 200: # partial
            print('resultCd=%d | recognizedText= %s' 
                  % (response.resultCd, response.recognizedText))
            resultText = response.recognizedText
        elif response.resultCd == 201: # final
            print('resultCd=%d | recognizedText= %s' 
                  % (response.resultCd, response.recognizedText))
            resultText = response.recognizedText
            break
        else:
            print('resultCd=%d | recognizedText= %s' 
                  % (response.resultCd, response.recognizedText))
            break

    print ("\n\n인식결과: %s \n\n\n" % (resultText))
    return resultText 
开发者ID:gigagenie,项目名称:ai-makers-kit,代码行数:25

示例14: queryByText

# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import secure_channel [as 别名]
def queryByText(text):

    channel = grpc.secure_channel('{}:{}'.format(HOST, PORT), UA.getCredentials())
    stub = gigagenieRPC_pb2_grpc.GigagenieStub(channel)

    message = gigagenieRPC_pb2.reqQueryText()
    message.queryText = text
    message.userSession = "1234"
    message.deviceId = "yourdevice"
        
    response = stub.queryByText(message)

    print ("\n\nresultCd: %d" % (response.resultCd))
    if response.resultCd == 200:
        print ("\n\n\n질의한 내용: %s" % (response.uword))
        #dssAction = response.action
        for a in response.action:
            response = a.mesg
        parsing_resp = response.replace('<![CDATA[', '')
        parsing_resp = parsing_resp.replace(']]>', '')
        print("\n\n질의에 대한 답변: " + parsing_resp + '\n\n\n')
        #return response.url
    else:
        print ("Fail: %d" % (response.resultCd))
        #return None 
开发者ID:gigagenie,项目名称:ai-makers-kit,代码行数:27

示例15: getText2VoiceUrl

# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import secure_channel [as 别名]
def getText2VoiceUrl(inText):

    channel = grpc.secure_channel('{}:{}'.format(HOST, PORT), UA.getCredentials())
    stub = gigagenieRPC_pb2_grpc.GigagenieStub(channel)

    message = gigagenieRPC_pb2.reqText()
    message.lang=0
    message.mode=0
    message.text=inText
    response = stub.getText2VoiceUrl(message)

    print ("\n\nresultCd: %d" % (response.resultCd))
    if response.resultCd == 200:
        print ("TTS 생성에 성공하였습니다.\n\n\n아래 URL을 웹브라우져에 넣어보세요.")
        print ("Stream Url: %s\n\n" % (response.url))
    else:
        print ("TTS 생성에 실패하였습니다.")
        print ("Fail: %d" % (response.resultCd)) 
开发者ID:gigagenie,项目名称:ai-makers-kit,代码行数:20
赞(0) 打赏
转载请注明来源:IT技术资讯 » Python grpc.secure_channel方法代码示例

评论 抢沙发

评论前必须登录!

 

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏