grpc._channel._InactiveRpcError: _InactiveRpcError of RPC that terminated with: status = StatusCode.INTERNAL - api

This is a gRPC service & client python program. After running the client script it throwing this error. I am pretty new to using APIs/ gRPC in particular. It would be great if I get to know what might be the problem. Installed gRPC library & few supporting libraries too.
Even though the server is running correctly, the communication through gRPC is terminating with the INTERNAL error status code. Running it on localhost.
return _end_unary_response_blocking(state, call, False, None)
File "/home/mark/anaconda3/envs/custom-model-server/lib/python3.8/site-packages/grpc/_channel.py", line 849, in _end_unary_response_blocking
raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
status = StatusCode.INTERNAL
details = "indices[0,350] = 1650751580 is not in [0, 30522)
[[{{node tf_bert_for_sequence_classification/bert/embeddings/Gather}}]]"
debug_error_string = "{"created":"#1629922773.170809502","description":"Error received from peer ipv4:127.0.0.1:8001","file":"src/core/lib/surface/call.cc","file_line":1066,"grpc_message":"indices[0,350] = 1650751580 is not in [0, 30522)\n\t [[{{node tf_bert_for_sequence_classification/bert/embeddings/Gather}}]]","grpc_status":13}"
'''

The solution for this was to check the byte array that was being passed to the function and make sure the length we were taking was of the array itself not in bytes. So we were able to do:
dimensions = len(byte_array)//4

Related

Error received: [SSL: BAD_LENGTH] bad length (_ssl.c:2408)

I made a game that can be controlled with voice command. To convert all the voice command into text I used IBM Cloud Speech to Text service. Everything is done except it is showing me the BAD LENGTH ERROR as you can see in the image.
This is the code for speech to text:
###############################################
#### Initalize queue to store the recordings ##
###############################################
CHUNK = 1024
# Note: It will discard if the websocket client can't consumme fast enough
# So, increase the max size as per your choice
BUF_MAX_SIZE = CHUNK * 10
# Buffer to store audio
q = Queue(maxsize=int(round(BUF_MAX_SIZE / CHUNK)))
# Create an instance of AudioSource
audio_source = AudioSource(q, True, True)
###############################################
#### Prepare Speech to Text Service ########
###############################################
# initialize speech to text service
authenticator = IAMAuthenticator('i3gkxvESZRUHnt0_Iv2PtMQaHd2roF1YgvTTIzq0tbop')
speech_to_text = SpeechToTextV1(authenticator=authenticator)
speech_to_text.set_service_url("https://api.eu-gb.speech-to-
text.watson.cloud.ibm.com/instances/54f44656-b15c-4a16-8dac-c5b782482f93")
actions = []
I got that error solved by just uninstalling all the packages and reinstalling the required one.
It will simply run successfully by just that and even if you receive that error in the future, try doing this process again. It will work.
Apart from this, I was not been able to find any other solution.
websocket.create_connection has an option enable_multithread. This ensures multithreading is correctly handled. Enabling this may fix.
Source

is there a way to setup timeout in grpc server side?

Unable to timeout a grpc connection from server side. It is possible that client establishes a connection but kept on hold/sleep which is resulting in grpc server connection to hang. Is there a way at server side to disconnect the connection after a certain time or set the timeout?
We tried disconnecting the connection from client side but unable to do so from server side. In this link Problem with gRPC setup. Getting an intermittent RPC unavailable error, Angad says that it is possible but unable to define those parameters in python.
My code snippet:
def serve():
server = grpc.server(thread_pool=futures.ThreadPoolExecutor(max_workers=2), maximum_concurrent_rpcs=None, options=(('grpc.so_reuseport', 1),('grpc.GRPC_ARG_KEEPALIVE_TIME_MS', 1000)))
stt_pb2_grpc.add_ListenerServicer_to_server(Listener(), server)
server.add_insecure_port("localhost:50051")
print("Server starting in port "+str(50051))
server.start()
try:
while True:
time.sleep(60 * 60 * 24)
except KeyboardInterrupt:
server.stop(0)
if __name__ == '__main__':
serve()
I expect the connection should be timed out from grpc server side too in python.
In short, you may find context.abort(...) useful, see API reference. Timeout a server handler is not supported by the underlying C-Core API of gRPC Python. So, you have to implement your own timeout mechanism in Python.
You can try out some solution from other StackOverflow questions.
Or use a simple-but-big-overhead extra threads to abort the connection after certain length of time. It might look like this:
_DEFAULT_TIME_LIMIT_S = 5
class FooServer(FooServicer):
def RPCWithTimeLimit(self, request, context):
rpc_ended = threading.Condition()
work_finished = threading.Event()
def wrapper(...):
YOUR_ACTUAL_WORK(...)
work_finished.set()
rpc_ended.notify_all()
def timer():
time.sleep(_DEFAULT_TIME_LIMIT_S)
rpc_ended.notify_all()
work_thread = threading.Thread(target=wrapper, ...)
work_thread.daemon = True
work_thread.start()
timer_thread = threading.Thread(target=timer)
timer_thread.daemon = True
timer_thread.start()
rpc_ended.wait()
if work_finished.is_set():
return NORMAL_RESPONSE
else:
context.abort(grpc.StatusCode.DEADLINE_EXCEEDED, 'RPC Time Out!')

Could not claim interface pyusb

I'm trying to use pyusb over usblib1.0 to read the data from an old Ps2 mouse using a Ps2 to USB adapter that represents it as a HID device.
I am able to access the device, but when I try to send it the GET_REPORT request over control transfer, it shows me this error:
[Errno None] b'libusb0-dll:err [claim_interface] could not claim interface 0, win error: The parameter is incorrect.\r\n'
Here is my code:
import usb.core as core
import time
from usb.core import USBError as USBError
dev = core.find(idVendor=0x13ba, idProduct=0x0018, address=0x03)
interface = 0
endpoint = dev[0][(interface, 0)][0]
dev.set_configuration()
collected = 0
attempts = 50
while collected < attempts:
try:
print(dev.ctrl_transfer(0b10100001, 0x01, wValue=100, data_or_wLength=64))
collected += 1
except USBError as e:
print(e)
time.sleep(0.1)
I'm using python 3.x in windows 10 (Lenovo g-510 if it matters to anyone)
The driver I installed is a usblib-win32 using Zadig
Any help will be appreciated!
Thanks
EDIT:
Tried using WIN-USB so that It'll work with usblib-1.0
It didn't find the device. Returned None from the usb.core.fןnd() function
Continuing with WIN-USB with usblib-1.0, I successfully found the device, but no it appears to have no configuration.
dev.set_configuration()
returns:
File "C:\Users\Idan Stark\AppData\Local\Programs\Python\Python36-32\lib\site-packages\usb\backend\libusb1.py", line 595, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 2] Entity not found
Any help will be appreciated, in usblib-1.0 or usblib-0.1, anything to make this work! Thank you!

Network Steganography StegoSip Tool

I am trying to use StegoSip tool coupled with Ekiga softphone. Finally Ekiga works, but when I run StegoSip, it gives me the warning that cb() takes exactly 3 arguments (2 given).
I found the function in the code and my opinion is that stegoSip does not recognize my conversation ( third argument ). I check the port and everything looks ok (SIP uses 5060 port).
I understand that the question is details, but I wasted too much time trying to fix this and I am desperate.
StegoSIP https://github.com/epinna/Stegosip
The problematic code:
def cb(self,i,nf_payload):
"""
Callback function of packet processing.
Get corresponding dissector and direction of packets with .getLoadedDissectorByMarker()
and send to the correct dissector using checkPkt() and processPkt().
"""
data = nf_payload.get_data()
pkt = stegoIP(data)
marker = nf_payload.get_nfmark()
dissector, incoming = dissector_dict.dissd.getLoadedDissectorByMarker(marker)
pkt.incoming = incoming
if not dissector:
nf_payload.set_verdict(nfqueue.NF_ACCEPT)
else:
dissector.checkPkt(pkt)
if pkt.extracted_payload:
dissector.processPkt(pkt, nf_payload)
return 1
The output is:
TypeError: cb() takes exactly 3 parameters (2 given)
Callback failure!

HTTPSConnectionPool Max retries exceeded

I've got a django app in production running on nginx/uwsgi. We recently started using SSL for all our connections. Since moving to SSL, I often get the following message:
HTTPSConnectionPool(host='foobar.com', port=443):
Max retries exceeded with url: /foo/bar
Essentially what happens is I've got the browser communicating with django server code, which then uses the requests library to call an api. Its the connection to the api that generates the error. Also, I've moved all our requests into one session (a requests session, that is), but this hasn't helped.
I've bumped up the number of uwsgi listeners since I thought that could be the problem, but our load isn't that high. Also, we never had this problem before SSL. Does anyone have some advice as to how to solve this problem?
Edit
Code snippet of how I call the API. I've posted it (mostly) verbatim. Note its not the code that actually fails, but the requests library that throws an exception when calling self.session.post
def save_answer(self):
logger.info("Saving answer to question")
url = "%s1.0/exam/learneranswer/" % self.api_url
response = {'success': False}
data = {'questionorder': self.request.POST.get('questionorder'),
'paper': self.request.POST.get('paper')}
data['answer'] = ",".join(self.request.POST.getlist('answer'))
r = self.session.post(url, data=simplejson.dumps(data))
if r.status_code == 201:
logger.info("Answer saved successfully")
response['success'] = True
elif r.status_code == 400:
if r.text == "Paper expired":
logger.warning("Timer has expired")
response['message'] = 'Your time has run out'
if r.text == "Question locked":
response['message'] = \
'This question is locked and cannot be answered anymore'
else:
logger.error("Unknown error")
self.log_error(r, "Unknown Error while saving answer")
else:
logger.error("Internal error")
self.log_error(r, "Internal error in api while saving answer")
return simplejson.dumps(response)
I've found that this error happens when some item in one of my views throws an exception. For example, when using the django 'requests' framework to post data to another URL:
r = requests.post(url, data=json.dumps(payload), headers=headers, timeout=5)
The downrange server was having connection issues, which threw an exception and that bubbled up and gave me the error you had above. I replaced with this:
try:
r = requests.post(url, data=json.dumps(payload), headers=headers, timeout=5)
except requests.exceptions.ConnectionError as e:
r = "No response"
And that fixed it (of course, I'd suggest adding in more error handling, but the above is the relevant subset).
You must disable validation like this
requests.get('https://google.com', verify=False)
You should specify your CA.
This Error occurs as a result of python script trying to connect to IBM service even before your wifi or ethernet connection is established. Have a try/catch to rectify or if trying to run as service then run service after network is established.