doucai9270 2017-08-14 14:04
浏览 308

如何使用python在grpc中使用Google进行身份验证?(我有一个可运行的PHP代码)

I got some .proto files from A service provider to get stock data.They give me a php code, but I need to use python.I try to do the same thing in python but I failed and failed.The official Docs is not very clear..and my programming skill is so low.. And this is my python code(core part),when I run this code,there will be a error message:"<_Rendezvous> of RPC that terminated with (StatusCode.UNIMPLEMENTED,Method not found:xxxxxxxxxxxxxxxxx.HistoricalQuoteService/getTodayM1Quotes)".I think I didn't connect to the server.When I add the code below:

options.append(update_metadata2)

The error message will changed to:"too many values to unpack"

symbol = common_pb2.Symbol()
symbol.code = "BABA"
symbol.market = common_pb2.US
symbol.type = common_pb2.Stock

market_request = marketData_pb2.MarketDataRequest()
market_request.symbol.code = symbol.code
market_request.symbol.market = symbol.market
market_request.symbol.type = symbol.type
market_request.language = common_pb2.zhHans

print(market_request)

try:
    path = os.path.abspath('.')
    pemPath = path + '/open_test_cert.pem'
    transport_creds = grpc.ssl_channel_credentials(open(pemPath).read())
    options = []
    update_metadata = {}
    update_metadata2 = {}

    update_metadata['UserName'] = 'xxxx'
    update_metadata['Password'] = 'yyyy'
    update_metadata2['grpc.ssl_target_name_override'] = 'open.test.yintongzhibo.com'
    options.append(update_metadata)
    # options.append(update_metadata2)
    channel = grpc.secure_channel("open.test.yintongzhibo.com:9002",transport_creds,options)



    # credentials , project= google_auth.default(scopes=(scope1,scope2,scope3))
    # credentials , project= google_auth.default()
    # http_request = google_auth_transport_requests.Request()
    # metadata_plugin = AuthMetadataPlugin(credentials,http_request)
    # google_auth_credentials = grpc.metadata_call_credentials(metadata_plugin)
    # ssl_credentials = grpc.ssl_channel_credentials(open(pemPath).read())
    # composite_credentials = grpc.composite_channel_credentials(ssl_credentials,google_auth_credentials)
    # channel = grpc.secure_channel("open.test.yintongzhibo.com:9002",composite_credentials)
    # channel = google_auth_transport_grpc.secure_authorized_channel(credentials,request,'open.test.yintongzhibo.com:9002')



    stub = historicalQuote_pb2_grpc.HistoricalQuoteServiceStub(channel)
    response = stub.getTodayM1Quotes(symbol)
    # stub = marketData_pb2_grpc.MarketDataServiceStub(channel)
    # response = stub.getMarketData(market_request)
    print(response.message)

except Exception as e:
    print (e)

So,How should I write python code to achieve the same function of the PHP code?And how can I get more error log?Thanks everyone! the PHP code is here: PHP code

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 安卓adb backup备份应用数据失败
    • ¥15 eclipse运行项目时遇到的问题
    • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
    • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
    • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
    • ¥50 成都蓉城足球俱乐部小程序抢票
    • ¥15 yolov7训练自己的数据集
    • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
    • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
    • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)