Browse Source

py3: encode messages on py3

On python3 send fails with TypeError: a bytes-like object is required,
not 'str', this patch solves this issue.

Closes-Bug: #1820154
Change-Id: I700462a9a5bcc66b2edf05e4e0396556e381a8c1
(cherry picked from commit 852c8098ca)
stable/stein
elajkat 2 years ago
committed by Lajos Katona
parent
commit
30326d75aa
1 changed files with 6 additions and 3 deletions
  1. +6
    -3
      networking_l2gw/services/l2gateway/agent/ovsdb/base_connection.py

+ 6
- 3
networking_l2gw/services/l2gateway/agent/ovsdb/base_connection.py View File

@ -24,6 +24,7 @@ from oslo_config import cfg
from oslo_log import log as logging
from oslo_serialization import jsonutils
from oslo_utils import excutils
import six
from networking_l2gw.services.l2gateway.common import constants as n_const
@ -267,11 +268,13 @@ class BaseConnection(object):
bytes_sent = 0
while retry_count <= n_const.MAX_RETRIES:
try:
data = jsonutils.dumps(message)
if not isinstance(data, six.binary_type):
data = data.encode()
if self.enable_manager:
bytes_sent = self.ovsdb_dicts.get(addr).send(
jsonutils.dumps(message))
bytes_sent = self.ovsdb_dicts.get(addr).send(data)
else:
bytes_sent = self.socket.send(jsonutils.dumps(message))
bytes_sent = self.socket.send(data)
if bytes_sent:
return True
except Exception as ex:


Loading…
Cancel
Save