From e48a97ffd43977282450a0f3892c9a15c89d735a Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 15 Feb 2018 11:27:53 +0100 Subject: [PATCH] pylightning: Filter out None arguments in JSON-RPC calls Passing them in doesn't hurt, but better to avoid ambivalences. Suggested-by: @graphite Signed-off-by: Christian Decker --- contrib/pylightning/lightning/lightning.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/contrib/pylightning/lightning/lightning.py b/contrib/pylightning/lightning/lightning.py index f9813b5ea..83b14945e 100644 --- a/contrib/pylightning/lightning/lightning.py +++ b/contrib/pylightning/lightning/lightning.py @@ -46,11 +46,16 @@ class UnixDomainSocketRpc(object): def call(self, method, payload=None): self.logger.debug("Calling %s with payload %r", method, payload) + if payload is None: + payload = {} + # Filter out arguments that are None + payload = {k: v for k, v in payload.items() if v is not None} + sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock.connect(self.socket_path) self._writeobj(sock, { "method": method, - "params": payload or {}, + "params": payload, "id": 0 }) resp = self._readobj(sock) @@ -58,7 +63,7 @@ class UnixDomainSocketRpc(object): self.logger.debug("Received response for %s call: %r", method, resp) if "error" in resp: - raise ValueError( + raise ValueError( "RPC call failed: {}, method: {}, payload: {}".format( resp["error"], method,