grpc-python

python grpc: setting timeout per grpc call

别来无恙 提交于 2021-02-11 14:57:22
问题 Is there a way to specify timeout per grpc call with python. I am experiencing more than 1 minute delay in receiving response. I want the api to return some error in case it is taking longer that specified time. I am using blocking grpc call. 回答1: You can look up the information you want at gRPC Python's API reference. Setting timeout should be as simple as: channel = grpc.insecure_channel(...) stub = ...(channel) stub.AnRPC(request, timeout=5) # 5 seconds timeout 来源: https://stackoverflow

How to send error details like as BadRequest

两盒软妹~` 提交于 2021-01-29 16:32:35
问题 I need send rich structured error details on gRPC error. I think it's maybe like this: fv = BadRequest.FieldViolation(field="login", description="Name is not unique") bad_request = BadRequest(field_violations=[fv]) context.abort(StatusCode.INVALID_ARGUMENT, bad_request.SerializeToString()) But is's wrong and send bytes in summary error text. I use grpcio==1.17.1 回答1: I got feedback on github issue https://github.com/grpc/grpc/issues/17601 Everything works in version 1.18.0 来源: https:/

Mocking gRPC status code ('RpcError' object has no attribute 'code') in Flask App

北慕城南 提交于 2021-01-29 14:51:50
问题 I have to create a unittest that should mock a specific grpc status code (in my case I need NOT_FOUND status). This is what i want to mock: try: # my mocked function except grpc.RpcError as e: if e.code() == grpc.StatusCode.NOT_FOUND: # do something My unittest until now looks like this: def mock_function_which_raise_RpcError(): e = grpc.RpcError(grpc.StatusCode.NOT_FOUND) raise e class MyTestCase(BaseViewTestCase): @property def base_url(self): return '/myurl' @mock.patch('my_func', mock

Use retryPolicy with python GRPC client

ぐ巨炮叔叔 提交于 2021-01-27 12:42:59
问题 I have tried really hard to use the embed retryPolicy of GRPC documentation (https://github.com/grpc/proposal/blob/master/A6-client-retries.md#retry-policy) but i fail to understand where i should setup the config in my code. Ideally i would like the python client to specify its retry policy but i am also interested to understand how to manage it from the server side. After some digging, i came up with this snipped but it does not work. import json from grpc import insecure_channel service

Use retryPolicy with python GRPC client

时光怂恿深爱的人放手 提交于 2021-01-27 12:32:17
问题 I have tried really hard to use the embed retryPolicy of GRPC documentation (https://github.com/grpc/proposal/blob/master/A6-client-retries.md#retry-policy) but i fail to understand where i should setup the config in my code. Ideally i would like the python client to specify its retry policy but i am also interested to understand how to manage it from the server side. After some digging, i came up with this snipped but it does not work. import json from grpc import insecure_channel service

Google cloud storage python client AttributeError: 'ClientOptions' object has no attribute 'scopes' occurs after deployment

自闭症网瘾萝莉.ら 提交于 2020-12-08 05:46:30
问题 I am using cloud storage with App Engine Flex. Out of the blue i start getting this error message after deploy succeeds The error is happening from these lines in my flask app. from google.cloud import storage, datastore client = storage.Client() File "/home/vmagent/app/main.py", line 104, in _load_db client = storage.Client() File "/env/lib/python3.6/site-packages/google/cloud/storage/client.py", line 110, in __init__ project=project, credentials=credentials, _http=_http File "/env/lib

Google cloud storage python client AttributeError: 'ClientOptions' object has no attribute 'scopes' occurs after deployment

半城伤御伤魂 提交于 2020-12-08 05:45:50
问题 I am using cloud storage with App Engine Flex. Out of the blue i start getting this error message after deploy succeeds The error is happening from these lines in my flask app. from google.cloud import storage, datastore client = storage.Client() File "/home/vmagent/app/main.py", line 104, in _load_db client = storage.Client() File "/env/lib/python3.6/site-packages/google/cloud/storage/client.py", line 110, in __init__ project=project, credentials=credentials, _http=_http File "/env/lib

Python not able to connect to grpc channel -> “failed to connect to all addresses” “grpc_status”:14

耗尽温柔 提交于 2020-12-08 05:34:31
问题 I'm getting the error below when trying to call a stub method. Any idea what is causing it? [bolt.api.handlers] 2019-08-21 20:07:57,792 ERROR handlers:1066: 'ResourceHandler' object has no attribute 'ontology_service_handler' Traceback (most recent call last): File "/bolt-webserver/bolt/api/onse/onse_handlers/ontology_service.py", line 17, in post ontology_id = await self.onse_stub.createOntology() File "/bolt-webserver/bolt/api/onse/onse_stub.py", line 41, in createOntology return self.stub

How to define a global error handler in gRPC python

柔情痞子 提交于 2020-05-25 07:41:26
问题 Im trying to catch any exception that is raised in any servicer so I can make sure that I only propagate known exceptions and not unexpected ones like ValueError, TypeError etc. I'd like to be able to catch any raised error, and format them or convert them to other errors to better control the info that is exposed. I don't want to have to enclose every servicer method with try/except. I've tried with an interceptor, but im not able to catch the errors there. Is there a way of specifying an

How to invoke a GRPC python client in locust?

萝らか妹 提交于 2020-04-18 05:45:52
问题 Is there any way to invoke GRPC python client in locust. The output is generated when I run the code locust -f 1.py . But the stats are not working. They are idle. users are swarming, but the stats are idle for everything 回答1: When you build your own client you need to report samples to locust yourself (because how would it otherwise know what you had done?) In current stable locust version you'd do something like: from locust import events, events.request_success.fire(request_type="grpc",