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