求大佬指导grpc python进行安全连接的代码(有PHP版本的代码,不过改写成python找不到对应的api。。555)
求大佬帮忙看看用python怎么写呢。。跪谢大佬了!
下面为php代码:

下面为我写不好用的python代码:
from __future__ import print_function
import grpc
import historicalQuote_pb2
import historicalQuote_pb2_grpc
import common_pb2
import common_pb2_grpc
import marketData_pb2
import marketData_pb2_grpc
import os
from google import auth as google_auth
from google.auth.transport import grpc as google_auth_transport_grpc
from google.auth.transport import requests as google_auth_transport_requests
def run():
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)
if __name__ == '__main__':
run()
相关推荐
grpc各语言使用官方示例代码.rar
grpc各语言使用官方示例代码;grpc各语言使用官方示例代码;grpc各语言使用官方示例代码grpc各语言使用官方示例代码
dad-joke-service:使用gRPC + protobuf,Golang服务器,PHP和Ruby客户端编写的微服务API
爸爸笑话服务 用gRPC和Protobuf编写的微服务API的示例。 该服务器是用Golang编写的,有两个示例客户端:一个在PHP中,一个在Ruby中。 这是一个示例,展示了使用gRPC和Protobuf编写微服务如何创建易于在任何主要语言(由gRPC支持,例如PHP,Ruby,Python,C#,Java等)中使用的API /服务。 启动并运行 可能需要一些时间来启动和运行它,因为它确实需要多种语言。 最简单的方法是使用自制软件安装所有这些东西: 。 brew install protobuf brew install protobuf-c brew install grpc 如果您在安装protobuf编译器时遇到问题,建议按照的说明进行操作。 如果要运行ruby客户端,建议使用brew install rbenv安装最新版本的ruby。 对于PHP,我还使用自制软
i686-grpc-1.27.2-2-any.zip
Windows下, 使用MinGw32编译的grpc, 含C++/C#/Object-C/PHP/Python/Ruby的Grpc编译工具, 及动态库,静态库, 及所需头文件
基于C++的gRPC跨语言通信框架设计源码
该项目是一款基于C++核心的gRPC跨语言通信框架设计源码,支持C、Python、Ruby等多种语言。项目包含11408个文件,涵盖多种编程语言,如C、Shell、PHP、MATLAB、C#、JavaScript、Go、Java、Swift等。此框架旨在实现高效、稳定的跨语言通信,适用于需要多语言交互的复杂系统开发。
远程服务调用文档
远程服务调用文档


Google技术社区

