tcalmant / jsonrpclib

A Python (2 & 3) JSON-RPC over HTTP that mirrors the syntax of xmlrpclib (aka jsonrpclib-pelix)
https://jsonrpclib-pelix.readthedocs.io/
Apache License 2.0
53 stars 24 forks source link

TypeError: 'NoneType' object is not subscriptable #59

Open guyco-redis opened 1 year ago

guyco-redis commented 1 year ago

Got the following traceback:

  File "/opt/redislabs/lib/python3.9/site-packages/jsonrpclib/jsonrpc.py", line 778, in __call__
    return self.__send(self.__name, kwargs)
  File "/opt/redislabs/lib/python3.9/site-packages/jsonrpclib/jsonrpc.py", line 652, in _request
    return response["result"]
TypeError: 'NoneType' object is not subscriptable

from what I could see ServerProxy._request performs self._run_request(request), which can return None, in which case check_for_errors returns the same None, and that is accessed.

tcalmant commented 1 year ago

Hi,

Would you have a use case that generates that situation, in order to prepare a unit test?

According to the specification, all requests except notifications must return a response object.

As a result, it would be more helpful to raise a TypeError exception with a message indicating that the server returned an invalid response . What is your opinion on the matter?

Note: in the master branch of this project, the issue would be on line 632

tcalmant commented 1 year ago

I have made an issue59 branch with an explicit error. Could you try if it fits your needs?

guyco-redis commented 1 year ago

Hi @tcalmant , unfortunately I don't have a use case that generates this bug, I only saw this traceback through production logs. Looking through _run_request which calls self.__transport.request, this might result by an error like errno.ECONNRESET, errno.ECONNABORTED or errno.EPIPE (which won't raise an exception)?

I think raising an informative TypeError should be good in this case