2020-03-18 10:42:44

by Mkrtchyan, Tigran

[permalink] [raw]
Subject: [PATCH] rpc: fix str to bytes conversion

fix back channel ping from server
---
rpc/rpc.py | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/rpc/rpc.py b/rpc/rpc.py
index c536384..d15cf06 100644
--- a/rpc/rpc.py
+++ b/rpc/rpc.py
@@ -693,8 +693,11 @@ class ConnectionHandler(object):
status, result, notify = tuple
if result is None:
result = b''
+ if isinstance(result, str):
+ result = bytes(result, encoding='UTF-8')
+
if not isinstance(result, bytes):
- raise TypeError("Expected string")
+ raise TypeError("Expected bytes, got %s" % type(result))
# status, result = method(msg_data, call_info)
log_t.debug("Called method, got %r, %r" % (status, result))
except rpclib.RPCDrop:
--
2.25.1


2020-03-24 21:19:07

by J. Bruce Fields

[permalink] [raw]
Subject: Re: [PATCH] rpc: fix str to bytes conversion

Applied.--b.

On Wed, Mar 18, 2020 at 11:40:31AM +0100, Tigran Mkrtchyan wrote:
> fix back channel ping from server
> ---
> rpc/rpc.py | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/rpc/rpc.py b/rpc/rpc.py
> index c536384..d15cf06 100644
> --- a/rpc/rpc.py
> +++ b/rpc/rpc.py
> @@ -693,8 +693,11 @@ class ConnectionHandler(object):
> status, result, notify = tuple
> if result is None:
> result = b''
> + if isinstance(result, str):
> + result = bytes(result, encoding='UTF-8')
> +
> if not isinstance(result, bytes):
> - raise TypeError("Expected string")
> + raise TypeError("Expected bytes, got %s" % type(result))
> # status, result = method(msg_data, call_info)
> log_t.debug("Called method, got %r, %r" % (status, result))
> except rpclib.RPCDrop:
> --
> 2.25.1