Преглед изворни кода

qmp.py: Encode json data before sending

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>
Eduardo Habkost пре 7 година
родитељ
комит
7e2b34f26e
1 измењених фајлова са 1 додато и 1 уклоњено
  1. 1 1
      scripts/qmp/qmp.py

+ 1 - 1
scripts/qmp/qmp.py

@@ -166,7 +166,7 @@ def cmd_obj(self, qmp_cmd):
         """
         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