[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 2/3] qmp.py: Encode json data before sending
From: |
Philippe Mathieu-Daudé |
Subject: |
Re: [Qemu-devel] [PATCH 2/3] qmp.py: Encode json data before sending |
Date: |
Tue, 13 Mar 2018 00:03:54 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 |
On 03/12/2018 07:55 PM, Eduardo Habkost wrote:
> On Python 3, json.dumps() return a str object, which can't be
> sent directly through a socket and must be encoded into a bytes
> object. Use .encode('utf-8'), which will work on both Python 2
> and Python 3.
>
> Signed-off-by: Eduardo Habkost <address@hidden>
> ---
> scripts/qmp/qmp.py | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/scripts/qmp/qmp.py b/scripts/qmp/qmp.py
> index 07c9632e9e..5c8cf6a056 100644
> --- a/scripts/qmp/qmp.py
> +++ b/scripts/qmp/qmp.py
> @@ -166,7 +166,7 @@ class QEMUMonitorProtocol(object):
> """
> self.logger.debug(">>> %s", qmp_cmd)
> try:
> - self.__sock.sendall(json.dumps(qmp_cmd))
> + self.__sock.sendall(json.dumps(qmp_cmd).encode('utf-8'))
> except socket.error as err:
> if err[0] == errno.EPIPE:
> return
>
http://lists.nongnu.org/archive/html/qemu-devel/2017-12/msg04047.html
;)