diff mbox series

[PULL,3/4] qmp.py: Encode json data before sending

Message ID 20180312221132.14141-4-ehabkost@redhat.com
State New
Headers show
Series [PULL,1/4] device-crash-test: New known crashes | expand

Commit Message

Eduardo Habkost March 12, 2018, 10:11 p.m. UTC
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 <ehabkost@redhat.com>
Message-Id: <20180312185503.5746-3-ehabkost@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 scripts/qmp/qmp.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

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