Skip to content

TypeError Exception raised when calling ConfigDBConnector().get_config in Python3 #44

@lvphuc133

Description

@lvphuc133

root@sonic:~# python3
Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.

import swsssdk
db = swsssdk.ConfigDBConnector()
db.connect()
cfg = db.get_config()
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.5/dist-packages/swsssdk-2.0.1-py3.5.egg/swsssdk/configdb.py", line 284, in get_config
(table_name, row) = key.split(self.TABLE_NAME_SEPARATOR, 1)
TypeError: a bytes-like object is required, not 'str'

FIX:
Current code:
for key in keys:
try:
(table_name, row) = key.split(self.TABLE_NAME_SEPARATOR, 1)

Proposed code change:
for key in keys:
if PY3K:
key = key.decode('utf-8')
try:
(table_name, row) = key.split(self.TABLE_NAME_SEPARATOR, 1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions